[Rt-commit] rt branch, 4.0/pass-default-for-date-fields, created. rt-4.0.8-195-gc74abd4

Jim Brandt jbrandt at bestpractical.com
Thu Nov 29 15:11:30 EST 2012


The branch, 4.0/pass-default-for-date-fields has been created
        at  c74abd4afdb1672fc4e0813a97c14f625866c636 (commit)

- Log -----------------------------------------------------------------
commit 6457ef4d07f29c9115f00ff7143bc5c64b9c3c02
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Nov 29 15:01:39 2012 -0500

    Add tests showing date CF value is lost on add attachment submit

diff --git a/t/web/cf_date.t b/t/web/cf_date.t
index 4ea93e4..be907b3 100644
--- a/t/web/cf_date.t
+++ b/t/web/cf_date.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 35;
+use RT::Test tests => 43;
 
 my ( $baseurl, $m ) = RT::Test->started_ok;
 ok $m->login, 'logged in as root';
@@ -184,3 +184,43 @@ diag 'check invalid inputs';
     $m->content_contains('test cf date:', 'has no cf date field on the page' );
     $m->content_lacks('foodate', 'invalid dates not set' );
 }
+
+diag 'retain values when adding attachments';
+{
+    my ( $ticket, $id );
+
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields    => { Queue => 'General' },
+    );
+    $m->content_contains('Select date', 'has cf field' );
+
+    $m->submit_form_ok(
+        { form_name => "TicketCreate",
+          fields    => {
+              Subject        => 'test 2015-06-04',
+              Content        => 'test',
+        },},
+        'Create test ticket'
+    );
+
+    ok( ($id) = $m->content =~ /Ticket (\d+) created/, "Created ticket $id" );
+    $m->follow_link_ok( {text => 'Jumbo'} );
+    $m->title_like( qr/Jumbo/ );
+
+    $m->submit_form_ok(
+        { form_name => "TicketModifyAll",
+          fields    => {
+            "Object-RT::Ticket-$id-CustomField-$cfid-Values" => '2015-06-04',
+          },
+          button => 'AddMoreAttach',
+      },
+        'Create test ticket'
+    );
+
+    $m->title_like( qr/Jumbo/ );
+
+    my $form_content = "name=\"Object-RT::Ticket-" . $id . "-CustomField-" . $cfid
+      . "-Values\" value=\"2015-06-04\" size=\"16\"";
+    $m->content_contains( $form_content, 'Date value still on form' );
+}

commit c74abd4afdb1672fc4e0813a97c14f625866c636
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Nov 29 11:02:33 2012 -0500

    Pass Default value to SelectDate
    
    The Default value is passed to EditCustomFieldDate and
    EditCustomFieldDateTime, but they don't pass it along to
    SelectDate. Without it, any value provided is lost when reloading
    the page but not submitting, like after adding an attachment.
    
    In SelectDate, Value was being defaulted with ||, but this
    incorrectly set it to undef when Value was the empty string
    and Default was undef.

diff --git a/share/html/Elements/EditCustomFieldDate b/share/html/Elements/EditCustomFieldDate
index c66640f..ceed2db 100644
--- a/share/html/Elements/EditCustomFieldDate
+++ b/share/html/Elements/EditCustomFieldDate
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 % my $name = $NamePrefix.$CustomField->Id.'-Values';
-<& /Elements/SelectDate, Name => "$name", current => 0, ShowTime => 0 &> (<%$DateObj->AsString(Time => 0)%>)
+<& /Elements/SelectDate, Name => "$name", current => 0, Default => $Default, ShowTime => 0 &> (<%$DateObj->AsString(Time => 0)%>)
 
 <%INIT>
 my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
diff --git a/share/html/Elements/EditCustomFieldDateTime b/share/html/Elements/EditCustomFieldDateTime
index a558884..0e5ad8d 100644
--- a/share/html/Elements/EditCustomFieldDateTime
+++ b/share/html/Elements/EditCustomFieldDateTime
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 % my $name = $NamePrefix.$CustomField->Id.'-Values';
-<& /Elements/SelectDate, Name => "$name", current => 0 &> (<%$DateObj->AsString%>)
+<& /Elements/SelectDate, Name => "$name", current => 0, Default => $Default &> (<%$DateObj->AsString%>)
 
 <%INIT>
 my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/SelectDate
index 18b42ad..898dde4 100644
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/SelectDate
@@ -57,7 +57,7 @@ unless ((defined $Default) or
                            $year+1900,$mon+1,$mday,                            
                            $hour,$min);   
 }
-$Value = $Value || $Default;
+$Value = $Default if defined $Default;
 
 unless ($Name) {
 	$Name = $menu_prefix. "_Date";

-----------------------------------------------------------------------


More information about the Rt-commit mailing list