Forums

date picker not working on edit forms

gluttonforpunishment 17 Jan, 2017
Hi

I have created a number of forms that enable me to edit data that was previously entered and for the most part they work fine however the datefields in the edit forms are not working. When I click into the field to update it the datepicker displays but the heading says undefined NaN and any date selected says NaN-Nan-NaN. Is there something different that I need to do to these fields to make them work?

Many thanks
Max_admin 17 Jan, 2017
Hi gluttonforpunishment,

If the date value in the date field on the form does not match the datepicker field value then this may occur, you need to convert the value to the correct format before the form is displayed, this is done using a "Custom code" action before the "HTML" action:

<?php
$form->data["date_field_name"] = date("d-m-Y", strtotime($form->data["date_field_name"]));


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gluttonforpunishment 18 Jan, 2017
Hi Max,

Thanks for your response however I had already changed the format within the date picker field to ensure that it matches the format within the database which is y-m-d (i have lots of date fields so this was easier that custom coding them all). The datepicker does not work on the edit form even when there was no data in the record. I have renamed all of the fields in the edit form as shown in your tutorial eg model[fieldname] and am wondering if this is messing with the code for the date picker? Do i need to load some sort of event to allow the date picker to work?

Thanks for your help
gluttonforpunishment 18 Jan, 2017
I have been playing with this and the problem is being caused because when saving the original form the date picker is adding 0000-00-00 into the field when there as been no date entered, is there a way to stop this? If I delete the date and then put the curser back in the field the date picker shows correctly. If I delete 0000-00-00 and save the form it 0000-00-00 is stilled saved into the database. HAs anyone had this issue before? I have done a search but not finding anything in the forums.
GreyHead 18 Jan, 2017
1 Likes
Hi gluttonforpunishment,

You might want to change the database table settings so that the default value is NULL or an empty string instead of 0000-00-00

You can also add a Custom Code action to the form On Submit event to check for 0000-00-00 strings and remove them if they are found
<?php
if ( $form->data['date_input'] == '0000-00-00' ) {
  form->data['date_input'] == '';
} 
?>

Bob
This topic is locked and no more replies can be posted.