editor optional date field
editor optional date field
I need to have a date field that is optional. I'm running into two specific issues (maybe by design?) with this:
1. If I use the server side date validation feature a date entry is always required (verified this in the editor date field example). Turning off validation allows non-date values to be entered.
2. Without validation the field may be left blank, but:
a. The value that shows in the table is "0000-00-00". This may be related to a MySQL implementation, but I can force it to display blank in the table using mRender.
b. If a row with "blank" date is edited, the field value in the form shows today's date, which is save on update even if the user does not enter anything.
Is there a way to make it work such that a date field is optional (allowed to be blank), but can be validated and edited without requiring a value.
1. If I use the server side date validation feature a date entry is always required (verified this in the editor date field example). Turning off validation allows non-date values to be entered.
2. Without validation the field may be left blank, but:
a. The value that shows in the table is "0000-00-00". This may be related to a MySQL implementation, but I can force it to display blank in the table using mRender.
b. If a row with "blank" date is edited, the field value in the form shows today's date, which is save on update even if the user does not enter anything.
Is there a way to make it work such that a date field is optional (allowed to be blank), but can be validated and edited without requiring a value.
This discussion has been closed.
Replies
[code]
public static function dateFormat( $val, $data, $opts ) {
$format = is_array($opts) ? $opts['format'] : $opts;
if ( $val === '' ) {
return true;
}
$date = date_create_from_format($format, $val);
if ( ! $date ) {
return isset( $opt['message'] ) ?
$opts['message'] :
"Date is not in the expected format";
}
return true;
}
[/code]
That will allow the validation to pass with an empty string (unless you use `dateFormat_required` as the validator).
Regards,
Allan
When in the database there is no date (0000-00-00) the editor ever shows the todays date when clicking on "edit" - so the user must delete the date-entry manually before saving.
[code]
public static function date_sql_to_format( $val, $data, $opts ) {
$date = explode(" ", $val);
$date = date_create_from_format('Y-m-d', $date[0]);
// Allow empty strings or invalid dates
if ( $date ) {
return date_format( $date, $opts );
}
return '';
}
[/code]
Could you link to the page showing the problem and confirm which version of Editor and the Editor libraries you are using?
Thanks,
Allan
I have the same problem : "When in the database there is no date (0000-00-00) the editor ever shows the todays date when clicking on "edit" - so the user must delete the date-entry manually before saving"
How can I solve it ?
Thanks
Thanks,
Allan
Yes jQuery UI's date picker. I hope that if there is no date (0000-00-00) or is null in the database the editor shows that field empty.
Thanks
Regards,
Allan
I am also having trouble with this. Was there ever an official solution?
I used this formatter function to handle the default value msql was returning:
HTH -- Rob
I've just committed a change to Editor which will correctly handle an empty date input set as null on the database. Note that this doesn't mean that
0000-00-00
isn't a valid date, it is, and is still handled as such, but null data is correctly handled now.This fix will be in Editor 1.3.2 which will be released shortly.
Allan
I am seeing something like this in the current implementation of Editor. I am creating an entry in the table that has a 0000-00-00 date, using inline editing if I edit any other field in that row editor is passing back the current date in place of the null in the post headers.
Can you show me the code use are using please, and ideally a link to the page in question so I can try to debug it?
Thanks,
Allan
The page is inside a corporate network so can't access it. Here are the js definitions for editor and some snippets of the json being passed back and forth. I tried with 2000-00-00 and it changed that as well.
The new field request:
then response
Then an edit where only priority was changed on the ui
Which shows that the approved date is being set to the current date.
Thanks!
Stephen
Hi Stephen,
Thanks for the details. I'm afraid I still don't have an immediate answer for you here - I can't quite figure out what is going wrong. The data you have above for "The new field request" looks really short - it doesn't submit the other fields?
However, the response shows that the data is obviously created okay. Then you do an edit and it submits the
created
data incorrectly - very odd!Are you using jQuery UI's date picker, a Bootstrap date picker, Chrome's date picker, or something else?
Thanks,
Allan
I created my own version of new / create as I wanted it to insert a blank row so that's why it looks a little different.
I am using the jQuery UI date picker for the two date fields.
I have played with it a bit more and the only time it updates is if is an "illegal" date. I changed it to be 2000-01-01 and its fine but if i put 2000-00-00 it modifies it.
Thanks,
-Stephen
Allan,
Any chance to take a look?
Thanks
Sorry I didn't get a chance to reply before.
It sounds like this is part of the behaviour of jQuery UI's date picker control - invalid dates become "today".
Perhaps the best bet would be to use
null
rather than0000-00-00
in the database for fields which don't have a value?Allan