Fix the Time field. Provide a getValueAsHtml method. Use it when displaying the form, so that the JS works correctly in displaying values. Fixes bug #12054 and works swell in the Thingy. The Thingy is my favorite asset now.
This commit is contained in:
parent
79ab978e49
commit
de6cf5875f
3 changed files with 60 additions and 28 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue