I have a link field and a boolean field. The link field will be displayed when the checkbox is ticked. However, the validation of the URL field stopped from working. The URL validation is working OK with no conditional rule.
I'm expecting to see the Manually entered paths should start with one of the following characters: / ? # error message when submitting the node. Without the validation, the front-end gets InvalidArgumentException: The internal path component 'www.google.com' is invalid. Its path component must have a leading slash, e.g. internal:/foo. in Drupal\Core\Url::fromInternalUri() (line 413 of core/lib/Drupal/Core/Url.php). error.
Steps to reproduce:
1. Manage dependencies.
2. Add link field in target field.
3. Add boolean field in controlled by.
4. The dependency would be the target field is visible when the control field is checked.
5. Edit or add a new node.
6. Tick checkbox.
7. Enter an URL that starts with "www" (eg. www.google.com) in the link field.
8. Save.
9. Check the node page.
| Comment | File | Size | Author |
|---|
Issue fork conditional_fields-3207751
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
larisse commentedHi! I think this patch will solve the problem!
Comment #3
larisse commentedComment #4
paulocsPatch #2 looks good to me.
Comment #5
colanIs this still a problem in 4.x?
Comment #6
larisse commentedHi!
This still a problem in 4.x version. I have installed and test and URL validation link field still break the site, like you can see in image below. It's works after apply the patch.
Comment #7
colanI just requeued #2 for testing.
Comment #8
kris77 commentedPatch in #2 works for me in 4.x dev.
Thank you so much @larisse
Comment #9
madelyncruz commentedThe patch works for me too. Thank you larisse!
Comment #10
thallesThanks everyone!
Comment #12
thallesComment #14
alexandru.dumitru commentedThis patch will trigger all errors, regardless if field if visible/hidden via conditional fields.
For example, apply the patch and hide a required field with conditional fields. Error will be triggered for the required field.
Comment #15
jonloh commentedI can confirm this patch triggered all errors regardless if the field is visible/hidden, as mentioned in #14.
Another issue is open to discuss this further: https://www.drupal.org/project/conditional_fields/issues/3344587
Comment #16
dqdThis "dirty fix" in here committed caused many trouble including #3344587: Support for field hidden by condition losing its required status So I reopen this issue to discuss a better solution.
Comment #17
heddnIs the dirty fix sufficient for us to mark a beta though?
Comment #20
joelpittet#16 was right to reopen this: the
return;committed in #2 treated the symptom, not the underlying problem. That change skips registering a dependent inconditional_fields_untriggered_dependentswhenever it has an error. As a result, untriggered fields keep both their errors and their values, which is the behaviour reported in #14, #15, and #3344587: Support for field hidden by condition losing its required status.The underlying bug is in
formValidate(): it never actually discarded an untriggered field's value. It wrote the replacement value to the widget wrapper's#parents(field_link_wrapper) instead of the field's real value location. Validation errors were therefore removed, but the invalid value still reached storage and caused the fatal from the original report. The reset option was also collected but never used.So this changes the approach: remove the
return;; only letvisible/!visiblemark a field untriggered, since other states leave it on the form; return early when the dependency cannot be evaluated; and discard the value at its real location while honouring reset.Worth weighing: saving while a condition is untriggered now clears that field's stored value. That matches the documented behaviour and D7, but it is also the concern raised in #3344587: Support for field hidden by condition losing its required status. The alternative is to keep values that may be invalid and allow them to reach storage.
ConditionalFieldLinkUrlValidationTestcovers both directions, the reset option, and this edit-time behaviour.