diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 88f6c29f4..d33e96454 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - fixed #12053: Thingy: View Thing Data - fixed #12062: Thingy: column headers missing from exported file - fixed #12063: Return URL from export doesn't work on non-default Thingy's + - fixed #12054: Thingy: Time fields and formatting 7.10.10 - fixed #12035: Story Manager - make keywords from Story view work diff --git a/lib/WebGUI/Form/TimeField.pm b/lib/WebGUI/Form/TimeField.pm index 402c3bc00..c5ccfb37b 100644 --- a/lib/WebGUI/Form/TimeField.pm +++ b/lib/WebGUI/Form/TimeField.pm @@ -157,6 +157,32 @@ sub getValue { #------------------------------------------------------------------- +=head2 getValueAsHtml ( ) + +Return the Form's value as a formatted time. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $value = $self->getOriginalValue(); + my $mysqlTime = ($value =~ $mysqlFormattedDate); + my $digits = ($value =~ /^\d+$/); + ##Format is fine + if ( $mysqlTime ) { + return $value; + } + ##Convert to mysql format + elsif ($digits) { + return $self->session->datetime->secondsToTime($value); + } + else { ##Bad stuff, maynard + return undef; + } +} + +#------------------------------------------------------------------- + =head2 headTags ( ) Set the head tags for this form plugin @@ -190,7 +216,8 @@ Renders a time field. sub toHtml { my $self = shift; - my $value = $self->getOriginalValue; + ##JS expects formatted time + $self->set('value', $self->getValueAsHtml); my $i18n = WebGUI::International->new($self->session); $self->set("extras", $self->get('extras') . ' onkeyup="doInputCheck(document.getElementById(\''.$self->get("id").'\'),\'0123456789:\')"'); return $self->SUPER::toHtml diff --git a/t/Form/TimeField.t b/t/Form/TimeField.t index 27c9f490c..ff3dbf3e2 100644 --- a/t/Form/TimeField.t +++ b/t/Form/TimeField.t @@ -50,7 +50,7 @@ my $testBlock = [ my $formType = 'text'; ##timeField is a text subclass -my $numTests = 37 + scalar @{ $testBlock }; +my $numTests = 40 + scalar @{ $testBlock }; plan tests => $numTests; @@ -86,48 +86,52 @@ WebGUI::Form_Checking::auto_check($session, 'TimeField', $testBlock); my $cntl; $cntl = WebGUI::Form::TimeField->new($session,{ }); is($cntl->getValue('10'), '10', 'no default, not mysql mode, all digits'); -is($cntl->getValue('00:00:10'), '10', 'no default, not mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('00:10'), '600', 'no default, not mysql mode, mysql formatted data, 2 pairs'); -is($cntl->getValue('00:10:00'), '600', 'no default, not mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('innocent'), undef, 'no default, not mysql mode, wrong data'); +is($cntl->getValue('00:00:10'), '10', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('00:10'), '600', '... mysql formatted data, 2 pairs'); +is($cntl->getValue('00:10:00'), '600', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('innocent'), undef, '... wrong data'); $cntl = WebGUI::Form::TimeField->new($session,{ format => 'mysql' }); is($cntl->getValue('10'), '00:00:10', 'no default, mysql mode, all digits'); -is($cntl->getValue('00:00:10'), '00:00:10', 'no default, mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('00:10'), '00:10', 'no default, mysql mode, mysql formatted data, 2 pairs'); -is($cntl->getValue('00:10:00'), '00:10:00', 'no default, mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('innocent'), undef, 'no default, mysql mode, wrong data'); +is($cntl->getValue('00:00:10'), '00:00:10', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('00:10'), '00:10', '... mysql formatted data, 2 pairs'); +is($cntl->getValue('00:10:00'), '00:10:00', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('innocent'), undef, '... wrong data'); $cntl = WebGUI::Form::TimeField->new($session,{ defaultValue => 0, }); is($cntl->getValue('10'), '10', '0 default, not mysql mode, all digits'); -is($cntl->getValue('00:00:10'), '10', '0 default, not mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('00:10'), '600', '0 default, not mysql mode, mysql formatted data, 2 pairs'); -is($cntl->getValue('00:10:00'), '600', '0 default, not mysql mode, mysql formatted data, 3 pairs'); +is($cntl->getValue('00:00:10'), '10', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('00:10'), '600', '... mysql formatted data, 2 pairs'); +is($cntl->getValue('00:10:00'), '600', '... mysql formatted data, 3 pairs'); $cntl = WebGUI::Form::TimeField->new($session,{ defaultValue => 1, }); is($cntl->getValue('10'), '10', '1 default, not mysql mode, all digits'); -is($cntl->getValue('00:00:10'), '10', '1 default, not mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('00:10'), '600', '1 default, not mysql mode, mysql formatted data, 2 pairs'); -is($cntl->getValue('00:10:00'), '600', '1 default, not mysql mode, mysql formatted data, 3 pairs'); +is($cntl->getValue('00:00:10'), '10', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('00:10'), '600', '... mysql formatted data, 2 pairs'); +is($cntl->getValue('00:10:00'), '600', '... mysql formatted data, 3 pairs'); $cntl = WebGUI::Form::TimeField->new($session,{ defaultValue => '55:55:55', }); is($cntl->getValue('10'), '00:00:10', 'mysql defaultValue, all digits'); -is($cntl->getValue('00:00:10'), '00:00:10', 'mysql defaultValue, mysql formatted data, 3 pairs'); -is($cntl->getValue('00:10'), '00:10', 'mysql defaultValue, mysql formatted data, 2 pairs'); -is($cntl->getValue('00:10:00'), '00:10:00', 'mysql defaultValue, mysql formatted data, 3 pairs'); +is($cntl->getValue('00:00:10'), '00:00:10', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('00:10'), '00:10', '... mysql formatted data, 2 pairs'); +is($cntl->getValue('00:10:00'), '00:10:00', '... mysql formatted data, 3 pairs'); $cntl = WebGUI::Form::TimeField->new($session,{ defaultValue => 0, format => 'mysql', }); is($cntl->getValue('10'), '00:00:10', '0 default, mysql mode, all digits'); -is($cntl->getValue('00:00:10'), '00:00:10', '0 default, mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('00:10'), '00:10', '0 default, mysql mode, mysql formatted data, 2 pairs'); -is($cntl->getValue('00:10:00'), '00:10:00', '0 default, mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('high noon'), undef, '0 default, mysql mode, mysql formatted data, bad data'); +is($cntl->getValue('00:00:10'), '00:00:10', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('00:10'), '00:10', '... mysql formatted data, 2 pairs'); +is($cntl->getValue('00:10:00'), '00:10:00', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('high noon'), undef, '... mysql formatted data, bad data'); $cntl = WebGUI::Form::TimeField->new($session,{ defaultValue => 1, format => 'mysql', }); is($cntl->getValue('10'), '00:00:10', '1 default, mysql mode, all digits'); -is($cntl->getValue('00:00:10'), '00:00:10', '1 default, mysql mode, mysql formatted data, 3 pairs'); -is($cntl->getValue('00:10'), '00:10', '1 default, mysql mode, mysql formatted data, 2 pairs'); -is($cntl->getValue('00:10:00'), '00:10:00', '1 default, mysql mode, mysql formatted data, 3 pairs'); - -__END__ +is($cntl->getValue('00:00:10'), '00:00:10', '... mysql formatted data, 3 pairs'); +is($cntl->getValue('00:10'), '00:10', '... mysql formatted data, 2 pairs'); +is($cntl->getValue('00:10:00'), '00:10:00', '... mysql formatted data, 3 pairs'); +$cntl->set('value', 10); +is($cntl->getValueAsHtml('10'), '00:00:10', 'getValueAsHtml, all digits'); +$cntl->set('value', '00:10'); +is($cntl->getValueAsHtml('00:10'), '00:10', '... minutes'); +$cntl->set('value', '00:10:00'); +is($cntl->getValueAsHtml('00:10:00'), '00:10:00', 'minutes, with empty seconds');