Hi,
I found that Conditional Validation is NOT working at all even as simple as for Required Validator

1.) Field Language List (select type) contains predefined values "English", "French", "Spanish" and "Other".

2.) Field Please Specify (text type) , user enters the language when Other is selected in Field Language List

I set a validation Required for Field Please specify when Other is selected in Field Language List but NOT working at all. Thanks

super bug

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

paulwdru created an issue. See original summary.

paulwdru’s picture

Hi,

I just realized that Condition Field must be entered using a Token for eg [node:field_language_list] instead of the field machine name after referring to http://www.rit.edu/drupal/api/drupal/sites%21all%21modules%21field_valid... and noticed that token_replace function is used.

Hopefully there'll be a clear guideline or even a better UI in the Conditional Validation so that users can choose or know what to be entered instead of falsely assuming a field machine name.

Thanks

paulwdru’s picture

Title: Conditional Validation is NOT working at all » Token in the Condition Field should return NULL when None is selected

Hi,

I found a bug when I want to check the value of the Condition Field whether is filled with a value using this token [field_collection_item:field_language_list:tid].

If I select None in a select list as Only local images are allowed. , the value returned from the Condition Field is exactly the same as the token entered [field_collection_item:field_language_list:tid].

The value to be returned should be NULL when None is selected. Could this bug be fixed ? Thanks

paulwdru’s picture

FileSize
4.03 KB

Hi,

With reference to #3, I modified field_validation_validator.inc as follows.

public function pass_condition() {
    $settings = $this->rule->settings;
    //print debug($settings);
    if (!empty($settings['condition'])) {
	  $condition_field = "";
      if (isset($settings['condition_wrapper']['condition_field']) && $settings['condition_wrapper']['condition_field'] != '' ) {
        $condition_field = token_replace($settings['condition_wrapper']['condition_field'], array($this->get_token_type() => $this->entity));
        
        // check if the token is converted otherwise returns a text-type NULL
        if ($condition_field == $settings['condition_wrapper']['condition_field']) {
          $condition_field = "NULL";
        }
      }

I just added 3 lines of codes.

        // check if the token is converted otherwise returns a text-type NULL
        if ($condition_field == $settings['condition_wrapper']['condition_field']) {
          $condition_field = "NULL";
        }

After adding the codes, now my settings work as intended below. If None is selected in the language, token [field_collection_item:field-language-list:tid] returns a text-type NULL for comparison.
patchfv
Only local images are allowed.

I don't know how to create a patch and not sure if this is ideal in solving the problem, just posted the codes for sharing and comment.

jalpesh’s picture

Assigned: Unassigned » jalpesh
FileSize
994 bytes

Here are the patch.

jalpesh’s picture

Status: Active » Needs review