I think it would be nice to have the option on the settings in your webform, to disable the browser validation.

If the checkbox has been enabled (disable HTML5 / browser validation) the form would need the additional tag 'novalidate'

Comments

djschoone created an issue. See original summary.

djschoone’s picture

Title: Add checkbox voor HTML5 / browser validation enable/disable novalidate » Add checkbox for HTML5 / browser validation enable/disable novalidate
cstpraveen’s picture

I can work with this. But I am a beginner. I need some time to do.

anthonyf’s picture

I've started working on a patch to add an option under webform advanced settings to disable automatic form validation by the browser. The aim is to add the 'novalidate' attribute to the form element if the user selects this option.

anthonyf’s picture

Assigned: Unassigned » anthonyf
anthonyf’s picture

StatusFileSize
new4.01 KB

I created a patch on 7.x-4.x-dev to add the "novalidate" option to webform configuration.
Run database updates after applying this patch as it adds a new column to the webform schema.
Find the new option in Form Settings, under Advanced Settings, "Disable browser validation".

anthonyf’s picture

Status: Active » Needs review
hamrant’s picture

Status: Needs review » Reviewed & tested by the community

Looks great, checked, everything works, move to rtbc

drclaw’s picture

Agreed! Patch applies and works as described. Thanks @ajfwebdev!

ivangelo’s picture

Thanks @ajfwebdev! The patch works.

frontmobe’s picture

Patch works perfectly, let's move this to rtbc. Nice functionality, thanks Anthony!

GrantI’s picture

Patch #6 works perfectly. However...

Remember to run the update.php script. For Drupal newbies if your domain is localhost/drupal then you need the URL localhost/drupal/update.php Very good idea to backup your database before you do so, just incase the worst happens.

danchadwick’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

What is the use case for not wanting browser validation? Why do you want to let the user submit the form and then report the error? We strive to add only the most essential features to webform to prevent feature bloat.

You can add no-validate by modifying the form in a custom module, for example.

If you feel you have a compelling argument for this feature that would apply to a fair number of webform users, please reopen this issue.

finex’s picture

Status: Closed (won't fix) » Active

Here is one usecase: if you're using jQuery plugins like Chosen or Selectric on required select field, the HTML5 validation system doesn't work.

anthonyf’s picture

Hi @DanChadwick,
The use case that prompted Patch #6 was that browser validation was not working correctly in some browsers. An alternative validation method was needed in those cases, but first there had to be a way to disable the default browser validation.

liam morland’s picture

Is this still a problem? In what ways was the browser validation not working correctly?

As it says in #13, a custom module could be used to adjust the form if desired.

john_b’s picture

This is absolutely needed. Errors in markup my be found in Webform sub-modules which have an official release, which trigger unwanted browser form validation, and which can be difficult to trace. I have encoutered this with select lists of prodcuts generated by Commerce Webform, a module whose maintainer is usually too busy to fix. Of the course the draconian approach is to say, 'just sort it, it is not a Webform issue'. Seems a bit harsh?

liam morland’s picture

Markup errors need to be fixed in the module that is creating the error. Remember you can always run a modded version of a module if you need to run a patch before it is accepted on d.o.

chris burge’s picture

It doesn't sound like this patch is getting in. Here's how I disabled HTML5 validation on all webforms:


/*
 * Implements hook_form_alter().
 */

function MY_MODULE_form_alter(&$form, $form_state, $form_id) {
  if (strstr($form_id,'webform') !== FALSE) {  
    // Prevent html5 validation. 
    $form['#attributes']['novalidate'] = '';
  }
}

If you only want this for certain forms, you can change the IF logic. Bottom line - you'll be controlling the 'novalidate' attribute in code, not in DB. That's why I disabled it on all webforms. My users creating webforms can't push code, so I disabled HTML5 validation for everyone.

Note: Modified per #21 below.

john_b’s picture

Thanks.

I probably will fix the module which is giving me a problem, unless someone esle does. Of course that is the right way to do it. A patch to disable browser validation would give users without those skills a helping hand: we do not want them to feel that the Drupal culture says, 'if you are not a coder, hire a coder or go away'.

liam morland’s picture

Title: Add checkbox for HTML5 / browser validation enable/disable novalidate » Support novalidate attribute
Version: 7.x-4.12 » 7.x-4.x-dev
Status: Active » Needs work

We also need a culture where problems are fixed at their source.

I am not completely opposed to this request. The patch needs a re-roll and needs to include tests for the attribute and the control for it.

The attribute should be set as the empty string; that is a valid way to display Boolean attributes:

$form['#attributes']['novalidate'] = '';

This can be improved once #2847484: Support boolean attributes in drupal_attributes() is committed.

blacklabel_tom’s picture

+1 this for D8 :)

liam morland’s picture

Please open a child ticket for D8.

blacklabel_tom’s picture

brtamas’s picture

liam morland’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 25: webform-7-4-18-novalidate-2637722-6-D7-02.patch, failed testing. View results

brtamas’s picture

jenlampton’s picture

Status: Needs work » Needs review

The last patch was submitted with no explanation, but I'm guessing we need to run the tests on it again? Changing status.

liam morland’s picture

Status: Needs review » Needs work

This patch needs re-roll so that it applies to the current tip of branch 7.x-4.x.

jenlampton’s picture

Priority: Minor » Major
Status: Needs work » Needs review
StatusFileSize
new3.19 KB

The difference between the two provided patches was the update number. webform_update_7431() vs webform_update_7432().

The patch in #28 applies (with fuzz) to 7.x-4.20 as well as 7.x-4.x.

Resubmitting here in the hopes of getting this in soon. All webforms with conditional requirements are currently broken in Chrome (or any browser that uses HTML5 validation). Hm, after stating that - bumping up priority to Major.

danchadwick’s picture

@jenlampton - Uh, wut? Is there a related issues for validation + conditionals being broken in Chrome? If not, please create one and reference it here.

I just created a webfom with a required field that is conditionally shown. It seems to work fine in Chrome (Windows, 76.0.3809.100) -- i.e. the required field is not required while it is hidden. Certainly we would want to fix the root issue (unless its impossible), rather than provide the work-around of novalidate.

liam morland’s picture

I think the best solution to this is to provide documentation for how to add the attribute using hook_form_alter(). This sound like something few people would want and it clutters the interface to have it. Someone could also write a module which implements this.

rudi teschner’s picture

I have similar problems with required hidden fields though my result from a combination of required hidden fields with chosen library.

I havent been able to find a solution directly within the library or the drupal module, but disabling browser validation seems to be a proper workaround - especially considering the required effort to find a solution.

At least it prevents the faulty browser validation in my case.

Since actual browser validation differs depending on the actual browser and thereby is a "risk factor" anyway ... it might not be a bad idea for complex webforms to add this option to the webform module.

I've also found some detailed evaluation of relying on browser validation to add some additional information to this issue: https://intopia.digital/articles/default-browser-error-messages/

jenlampton’s picture

Priority: Major » Normal

Ah, thanks @Rudi Teschner, I have confirmed that my site with the broken required hidden fields also has Chosen, so it's likely that library is affecting the webform's hidden required fields. I was not able to reproduce bug with only drupal core + webform, ctools, & views. Changing status back to Normal.

I'm still applying this patch to 7.x-4.21, but if the recommended approach for adding the novalidate attribute is to use a custom module, we should mark this issue as closed (won't fix), and those of us using the patch should adapt our sites appropriately.

liam morland’s picture

Status: Needs review » Closed (won't fix)