I'm trying to use the filter possibility against the keyword 'now'. But with Views 3, the value in the setting form is not saved. I have debugged this now for 2 hours but I cannot find the difference in Views 2 and Views 3 that makes the date filter form to not save the value 'now' in the filter settings form.

Does someona has an idea, what wrong here?

CommentFileSizeAuthor
#1 views-date_now_form_validation-dev.patch555 bytesayalon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ayalon’s picture

Title: Filter by Date >= 'now' does not work with Views 3 » Filter by Date >= 'now' does not work with Views 3 because views form validators are not extecuted
Priority: Normal » Critical
Status: Active » Needs review
FileSize
555 bytes

I finally found the the codeline, that kills the form validation:

current dev version code

function views_ui_standard_form_buttons(&$form, &$form_state, $form_id, $name = NULL, $third = NULL, $submit = NULL) {
  $form['buttons'] = array(
    '#prefix' => '<div class="clear-block"><div class="form-buttons">',
    '#suffix' => '</div></div>',
  );

  if (empty($name)) {
    $name = t('Update');
  }

  // remove default validate handler
  $form['#validate'] = array();

fixed and working code

function views_ui_standard_form_buttons(&$form, &$form_state, $form_id, $name = NULL, $third = NULL, $submit = NULL) {
  $form['buttons'] = array(
    '#prefix' => '<div class="clear-block"><div class="form-buttons">',
    '#suffix' => '</div></div>',
  );

  if (empty($name)) {
    $name = t('Update');
  }

  // remove default validate handler
  // $form['#validate'] = array();

dawehner’s picture

Priority: Critical » Major

Mh critical.
Critical is a wsod or something which brakes your site.

This isn't a difference between views2 and views3.
Can you please explain why this fixes the issue?
The validation just checks. The "now" is part of the php date-functions.

But yes i can reproduce the issue here. This was seen before on d7, too.
I fear that the real problem is somewhere else.

ayalon’s picture

The point is, that the form validation are not executed.

Because of the code line above, all form validation are reset. I set some breakpoints and the validation form of the date module (date/includes/date_api_filter_handler.inc) is never executed.

The problem has nothing todo with the word "now" and no relation to the date function.

The problem is, that the form validation not happens and therefore the value is not validated and saved.

And yes, its critical: Think about a page, that uses this functionality. All entries will be displayed and nothing will be filtered. Can be very very ugly.

dawehner’s picture

Well this is major but it's not critical afaik.

The main question is why this works on views 2.x. This line didn't changed in views 3.x
I guess the problem is somewhere else.

cossme’s picture

sorry, I haven't found a cause yet though searching and very interested in a solution ... so subscribing

merlinofchaos’s picture

I can't duplicate this.

Further, 'now' is not a keyword that Views date filters support.

Is this an issue only with date.module?

merlinofchaos’s picture

Ok, untrue. I can duplicate this on both Views 2 and Views 3 using the user: name filter.

merlinofchaos’s picture

Status: Needs review » Fixed

Ironically, fixing the validation makes user: name work...but I can't get date to work. But date seems to have its own special Specialness that I don't understand. I think the core problem here is fixed. In all branches.

ayalon’s picture

Does this mean, that 'now' filter in Views 3 works? Did you commit anything?

ayalon’s picture

I tested this with the version of 18.11 Dev and the bug still exists. You cannot validate the form, the value "now" is not saved.

ayalon’s picture

Merlinofchaos:

Instruction on how to reproduce this:

- Create a view with 2 fields: Node Title and a CCK Date field
- Now filter for the CCK Date field
- Try to save the keyword 'now' as a default filter
- Because of the form validation problem, you will NOT be able to save the keyword 'now'
- If you set a breakpoint, the form validation will never be executed.
- If you comment out the line above, the form validation will be executed and the value will be saved.

merlinofchaos’s picture

I fixed the problem with validation, yes, using the patch provided. The views filters that also suffered the problem was fixed.

I don't understand why the 'date' filter continues to not work, but that's date.module. I am not going to debug date.module to figure out what's going on. Unfortunately, I do not have the time for that.

ayalon’s picture

Thanks for your response.

Using the 3.x dev from 21-11-2010 and the latest date module 21-11-2010 fixed all the issues with the form validation and now filter. Thanks for your help.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Rob T’s picture

Thanks for the patch, which works well in a pinch until I can update our Views module in a few days on a particular site.