Date input (SOLVED)

A place for users and developers of the Xataface to discuss and receive support.

Date input (SOLVED)

Postby cantlep » Wed Jun 02, 2010 2:56 am

Hiya,

When entering a date in a field in "New Record". The calendar function allows the date to be selected..Brilliant. However, when it's actually copied into the field, it's in US format (MM/DD/YY). Is there a way to make it UK format (DD/MM/YY). I have it in UK record format once the details have been "saved"..it's just in the new record bit I'd like to change it. Is this something in Xataface or some other locale type setting on the system?

Thanks

Paul
Last edited by cantlep on Mon Jun 07, 2010 1:52 pm, edited 1 time in total.
cantlep
 
Posts: 172
Joined: Fri Mar 05, 2010 2:14 am

Re: Date input

Postby shannah » Mon Jun 07, 2010 9:45 am

Yes. You can adjust the format that the calendar widget accepts for dates using the widget:ifFormat directive in the fields.ini file:
Code: Select all
[myfield]
widget:ifFormat="%Y-%m-%d %I:%M %P"


The format should use the same variables as the strftime function:
http://php.net/manual/en/function.strftime.php
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Date input (SOLVED)

Postby cantlep » Mon Jun 07, 2010 1:52 pm

Hi Steve,

Cheers. Works like a charm.

Thanks

Paul
cantlep
 
Posts: 172
Joined: Fri Mar 05, 2010 2:14 am

Re: Date input (SOLVED)

Postby marcelo.guedes » Wed Nov 14, 2012 2:25 pm

Hi.

This solution is not working any more in 2.0alpha1.

When I insert the ifFormat parameter I have date inconsistencies. For instance:

For widget:ifFormat="%d/%m/%Y", when I click on the calendar icon and select the date "1st February, 2012" it shows in the field: "01/02/2012". Nice, perfect. But when I save it, the database stores "2011-01-02" or the date "2nd January, 2011". More than that, when I try to find the date in the calendar again the select date is different from both, showing "4th July, 2007".

I have no idea what's going on here. I tried to created the function <datefield>__pull in this way:

Code: Select all
  function datefield__pull(&$record){
    if ($record->val('datefield') == NULL) {
      return '';
    }else{
      return date('d/m/Y', strtotime($record->strval('datefield')));
    }
  }


However, it only created a new level of inconsistencies and it didn't solved the issue.

Ideas?
marcelo.guedes
 
Posts: 7
Joined: Wed Nov 14, 2012 6:09 am

Re: Date input (SOLVED)

Postby shannah » Wed Nov 14, 2012 3:14 pm

I have added this issue to the issue tracker
http://bugs.weblite.ca/view.php?id=1179
http://bugs.weblite.ca/view.php?id=1180 (duplicate for 1.3.x branch)

And I have fixed the issue.

You can get the update by replacing your Dataface/FormTool/calendar.php file with the one at
http://weblite.ca/svn/dataface/core/tru ... lendar.php

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Date input (SOLVED)

Postby marcelo.guedes » Wed Nov 14, 2012 4:26 pm

Hi!

It worked here, requiring all the modifications together:
delegate classes <datefield>__pullValue as reported in forum
+
widget:ifFormat = "%d/%m/%Y"
+
the new calendar.php file.

Suggestion:
This calendar.php solution can't deal with empty field. It returns a old date instead (strange it seems, different old dates when using or not using ifFormat). To deal with NULL field, I would like to suggest a small modification in function pushValue:

Code: Select all
33,37d32
<
< if (trim($element->getValue()) == NULL)   {
<   return NULL;
< }
<
38a34
>    


It will deal with NULL and white spaces. My function is now:

Code: Select all
   /**
    * @brief Added support to transform date values in alternate formats
    * as provided by the widget:ifFormat directive.
    * http://xataface.com/forum/viewtopic.php?f=4&t=5345
    */
   function pushValue(&$record, &$field, &$form, &$element, &$metaValues){
      $table =& $record->_table;
      $formTool =& Dataface_FormTool::getInstance();
      $formFieldName = $field['name'];

      if (trim($element->getValue()) == NULL)   {
         return NULL;
      }

      if ( @$field['widget']['ifFormat'] ){
         $ts = strptime($element->getValue(), $field['widget']['ifFormat']);
         $ts = mktime($ts['tm_hour'], $ts['tm_min'], $ts['tm_sec'],
                     $ts['tm_mon']+1, $ts['tm_mday'], ($ts['tm_year'] + 1900));
            return date('Y-m-d H:i:s', $ts);
      } else {
         return $element->getValue();
      }
      
   }


Here it is working just as expected now. I didn't test enough about the cases without ifFormat but maybe it is a good idea to be careful because they are treated in different ways.

Thank you very much.
marcelo.guedes
 
Posts: 7
Joined: Wed Nov 14, 2012 6:09 am

Re: Date input (SOLVED)

Postby shannah » Wed Nov 14, 2012 4:33 pm

Thanks for pointing this out. I have made some changes in the trunk to address this issue.
http://weblite.ca/svn/dataface/core/tru ... lendar.php
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Date input (SOLVED)

Postby marcelo.guedes » Wed Nov 14, 2012 4:42 pm

Updated here. Working like a charm.
marcelo.guedes
 
Posts: 7
Joined: Wed Nov 14, 2012 6:09 am


Return to Xataface Users

Who is online

Users browsing this forum: Google [Bot] and 6 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved