Thursday, May 8, 2014

Re: Using JQuery UI Datepicker for formatted date fields (dd/mm/yy)

I´ve solved this type of issues with a hidden field having the value in sql format (YYYY-MM-DD ) and formatting the date for user with php in the text field. ( http://php.net/manual/en/function.date.php )

jquery can set 2 fields with the diferents formats. ( http://jqueryui.com/datepicker/#alt-field )



El martes, 6 de mayo de 2014 11:00:32 UTC-3, Dario Savella escribió:
I was able to make this work without much of a problem using dates in the format they arrive from the database.
But that's not an acceptable for the users... and here I started having problems.

It's easy enough to set the dateFormat of the datepicker (as suggested in posts I've seen around), but that does not seem enough.
When editing a row, dates are still displayed in ISO format and modified ones, that have been returned with the correct format by the datepicker, are not understood by the Model/MySQL that ends up saving the row with messed up values.
I build the field with:
        echo $this->Form->input('date_start', array(
            'type' => 'text',
            'class' =>'datepicker',
            'size' => 10
        ));

Before I start writing an Helper (that perhaps generates an hidden field with the date in ISO format and the necessary Javascript to move the displayed value to&from and reformatting as necessary)...

I was wondering if there's a better solution around I just have not seen...

Can anyone help ?

Dario

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: