Closed (works as designed)
Project:
Date
Version:
5.x-2.0-rc
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 May 2008 at 15:10 UTC
Updated:
23 Jun 2008 at 15:19 UTC
I've written a script to automatically create a bunch of CCK nodes.
$node = array();
$node['uid'] = $user->uid;
$node['name'] = $user->name;
$node['type'] = 'myCalendarNode';
$values['field_day'][0]['value'] = $date;
...
drupal_execute($node['type'] . '_node_form', $values, $node);
As you can see one of the fields has the CCK type Date.
When assigning the field the widget type "Text Field with jquery pop-up calendar" validation throws an error: "Day 2 2 not valid"
When assigning the field the widget type "Text Field with strtotime validation" nodes get created properly
The following function reveals another symptom:
date_popup_input_value($element) {
$input = $element['#value']['date'];
...$element['#value']['date'] doesn't exist when jquery is used because
$element['#value'] = '2008-05-14';
This string gets truncated to '2' when accessed by ['date'].
Comments
Comment #1
karens commentedUpdate to the latest dev version of the Date module.
Comment #2
p_alexander commentedemeidi, has this fixed your problem? I'm still getting it on the most recent DEV.
Comment #3
emeidi commentedIssue still not fixed.
Neither
$values['field_day'][0]['value'] = $date . 'T00:00:00';nor
$values['field_day'][0]['value']['date'] = $date;works when field type uses the JQuery Pop-Up Calendar.
Comment #4
emeidi commenteddate_text_input_value() expects the value to be an array. When I'm submitting an array ...
$values['field_day'][0]['value']['date'] = $date . 'T00:00:00';... there are other errors showing up:
When reverting back to
$values['field_day'][0]['value'] = $date . 'T00:00:00';the first time date_text_input_value() is called the string gets truncated to '2' (generally speaking: the first char of the year) and doesn't get validated. The corresponding node ends up with no date set. All further nodes have the correct date set.
So ... in order to get this mess up and running, I decided to hack date_text_input_value():
Comment #5
karens commentedI suggest using node_save() instead of drupal_execute(). The date elements do some complex handling using #process and #validate and it could be quite difficult to get all those values right since you have to build a form element with all the complexities of the form handling taken into account.
On the other hand node_save() it very straightforward -- you need to create a node with the values exactly as they are stored in the database and everything usually works just fine.
Comment #6
emeidi commentedThank you for your suggestion, but switching from drupal_execute() to node_save() won't cure bugs in the Date module, will it? It's still there, buried in this mess ...
Choosing drupal_execute() over node_save() was suggested in a few places:
[development] programmatic creation of node
Quick-and-dirty CCK imports
Comment #7
karens commentedNote the rest of the comment you quoted above:
And my response to Quick-and-dirty CCK imports.
And note what I ran into when I tried it in http://drupal.org/node/258572.
It is not a 'bug' in the Date module that this doesn't work well. It works for simple, uncomplicated fields. It doesn't always work for complicated fields.