Hi all,
See the bug :
Create a new content type :
- Add a select box with "Option 1" and "Option 2"
- Add a text field
-----------------------------
Set condition :
- Make required the text field when "Option 1" is selected. So is not required when "Option 2" is selected.
-----------------------------
Create a new content :
- Select "Option 1" and write something in the text field, now save : That work (because it's required).
- Select "Option 2" and write something in the text field : That does not work (because it is not required).
What is expected ?
When you select the "Option 2", the text field have to be not required and when I save the text field have to be saved.
What happend ?
The text field is not required (so it's ok) but when I want to save, the value of text field is not saved.
Why ?
In conditional_fields.module, i've that :
// Remove submitted values.
unset($field_values_location[$dependent['#field_name']]);
It's very usefull when the dependent have to be not visible when condition is not triggered. But for other type of condition, it's a problem to fix.
How fix ?
Just a suggestion :
// Return true if we have to remove possible submitted values
if(conditional_fields_unset_field($dependent, $form))
{
// Remove submitted values.
unset($field_values_location[$dependent['#field_name']]);
}
And the function :
/**
* Check conditions and evaluate whether the possible submitted values have to
* be removed
* @return boolean Return TRUE if we have to remove submitted values
*/
function conditional_fields_unset_field($dependent, $form)
{
$dependencies = $form['#conditional_fields'][$dependent['#field_name']]['dependees'];
foreach ($dependencies as $dependency) {
if($dependency["options"]["state"] == "visible")
{
return TRUE;
}
}
return FALSE;
}
Bye bye
Nicolas
Comments
Comment #1
delacosta456 CreditAttribution: delacosta456 commentedhi
Please i am not expert but it look's like i am having something similar but it another scenario an may be you can help
i post it here https://www.drupal.org/node/2892321
thanks