If I use Driven NEP to disable modification of a CCK date field, submission of a node form (editing the node) fails validation, with the messsage "the date(s) are invalid". Perhaps this is related to my (solved) programmatic date comment_driven issue http://drupal.org/node/942932?

Comments

arhak’s picture

Status: Active » Postponed (maintainer needs more info)

I need to know exactly how to reproduce it

I tried with dropdown widget and there was no trouble (date-6.x-2.4 but 2.6 doesn't look so different)

since NEP only turns #access into FALSE, it should work,
it is unobtrusive, and complies FAPI specs

PS: I might be missing something, this was just a quick trial

obrienmd’s picture

Will put together another trial to test the issue happening on a production setup ASAP. Thanks for the feedback, arhak.

obrienmd’s picture

Status: Postponed (maintainer needs more info) » Active

OK, did some more testing. To reproduce:

1) Install vanilla Drupal 6.19
2) Add comment_driven (tested reccommended and 1.x-dev), driven (tested recommended and 1.x-dev), date modules (tested 2.4 and 2.6)
3) Add a content type with a date field (tested select list and text field w/ date popup)
4) Make the date field required
5) Turn on comment driven for the date field
6) Turn on NEP for the date field

For all permutations of the above tested parameters, editing the node after initial creation (ie: when the NEP date property is hidden) results in the error message "There are errors in : The dates are invalid." after submission.

Driving the property through comment driven works great.

obrienmd’s picture

If I make the field not required, this problem no longer occurs - this leads me to believe it has something to do with checking if field is required in date's validation code.

arhak’s picture

configuration of the date field would be helpful (for instance, you don't mention its granularity)

the only place in the whole date module where that string exists is in date_elements.inc, near line 480

    if (!$field['required'] && (empty($from_date) || empty($to_date))) {
      $item = date_element_empty($element, $form_state);
      $errors[] = t('The dates are invalid.');
    }

and it clearly says if (!$field['required']) ... which is precisely the opposite of what you describe regarding making the field required

arhak’s picture

its really odd,
I'll have to try it in a fresh install

BTW, which value did you assigned to the date field on node creation?

PS: the date I tried in my test has
- Default value: blank
- Default value for To date: same as From date
- Years back and forward: -3:+3
- ... oh.. it is not required (then my test was not accurate)
- granularity up to the minute

arhak’s picture

indeed, making it required brings the error

arhak’s picture

Status: Active » Closed (works as designed)

as I previously said @#1,
Driven NEP only turns #access into FALSE
which leaves $element['#post'] without a $field_name index (near line 391)
while the return statement (near line 385) saves the situation for non-required dates

then, turning #access=FALSE makes $element['#post'][$field_name] undefined, then $posted is also undefined (which is already a bug, but doesn't causes the current issue)
and immediately bellow it $field results undefined too, since $form_state['#field_info'][$field_name] is also undefined (right now I won't look why it is, I guess it is part of date's submission workflow)
Note: $field_name and $element['#field_name'] hold the same value in my test, that is why I used them indistinctly in the above description

  // If the whole field is empty and that's OK, stop now.
  if (empty($element['#post'][$field_name]) && !$element['#required']) {
    return;
  }
  
  // Repeating dates have a different form structure, so get the
  // right item values.
  $item = isset($form_values[$field_name]['rrule']) ? $form_values[$field_name] : $form_values[$field_name][$delta];
  $posted = isset($form_values[$field_name]['rrule']) ? $element['#post'][$field_name] : $element['#post'][$field_name][$delta];
    
  $field = $form_state['#field_info'][$element['#field_name']];

then, if $field is undefined the code @#5 triggers the error because !$field['required'] yields TRUE

according to FAPI #access=FALSE should be supported by date module,
ergo, not our bug

PS: I recommend opening a new issue on the date module, because they wouldn't distinguish their fault mixed with Driven API

arhak’s picture

BTW for the date module my proposal would be the following

  // If the whole field is empty and that's OK, stop now.
  if (empty($element['#post'][$field_name]) && (!$element['#required'] || (isset($element['#access']) && !$element['#access']))) {
    return;
  }
obrienmd’s picture

Thanks, arhak.

Posted a new issue w/ patch to date at: http://drupal.org/node/976254

arhak’s picture

Project: Comment driven » Driven API

moved to its actual project