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.

CommentFileSizeAuthor
#6 after-patch.png74.8 KBlarisse
#6 before-patch.png271.91 KBlarisse
#2 3207751_2.patch479 byteslarisse
Command icon 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

madelyncruz created an issue. See original summary.

larisse’s picture

StatusFileSize
new479 bytes

Hi! I think this patch will solve the problem!

larisse’s picture

Status: Active » Needs review
paulocs’s picture

Status: Needs review » Reviewed & tested by the community

Patch #2 looks good to me.

colan’s picture

Version: 8.x-1.0-alpha10 » 4.x-dev
Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Is this still a problem in 4.x?

larisse’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community
StatusFileSize
new271.91 KB
new74.8 KB

Hi!

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.

colan’s picture

I just requeued #2 for testing.

kris77’s picture

Patch in #2 works for me in 4.x dev.

Thank you so much @larisse

madelyncruz’s picture

The patch works for me too. Thank you larisse!

thalles’s picture

Thanks everyone!

  • larisse authored e150739 on 4.x
    Issue #3207751 by larisse: URL validation of link field doesn't work
    
thalles’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

alexandru.dumitru’s picture

This 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.

jonloh’s picture

I 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

dqd’s picture

Status: Closed (fixed) » Needs work

This "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.

heddn’s picture

Is the dirty fix sufficient for us to mark a beta though?

joelpittet made their first commit to this issue’s fork.

joelpittet’s picture

Status: Needs work » Needs review

#16 was right to reopen this: the return; committed in #2 treated the symptom, not the underlying problem. That change skips registering a dependent in conditional_fields_untriggered_dependents whenever 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 let visible/!visible mark 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. ConditionalFieldLinkUrlValidationTest covers both directions, the reset option, and this edit-time behaviour.