Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I try to theme the output of my field called website using the hook_form_alter function
I try to add a javascript function to validate inline
$form['field_website'][und][0]['url']['#attributes']['onblur'] = 'validateWebsite(value)';
$form['field_website'][und][0]['url']['#field_prefix'] = '<span id="websiteError" class="formerror" style="display: none;">You must enter a valid website address</span>';
It works for email field but not for link field. Do you know why ?
Comments
Comment #1
jcfiala CreditAttribution: jcfiala commentedI couldn't say, no. I don't know anything about this validateWebsite that you're using, or your site. Does the 'onblur' attribute appear for the url field? Are you sure your form_alter is being called? (I often find that it doesn't until I clear cache.) Do you have a javascript error on the page that's preventing the code from firing?
Comment #2
JKingsnorth CreditAttribution: JKingsnorth commentedNo further information supplied for a long while, and debugging suggestions have been provided, closing the issue. Please reopen if you still require support.