It would be great if we could define a list of webforms to include clientside validation and to leave the rest unaffected.
I'm also attaching a patch with a first approach to include this feature, it includes a global settings page at /admin/config/user-interface/clientside-validation and a per webform setting at /admin/structure/webform/manage/{webform}/settings under "THIRD PARTY SETTINGS"

Remaining tasks

  1. Remove all the references of webform or any contrib module (#21)
  2. Raise PR for just the changes required to facilitate webform related changes from other module (like the configuration form and all) (#21)
  3. Create new contributed module for the bridge between webform and clientside_validation so it can be added for all those who need without increasing the scope of either clientside_validation or webform modules (#21)
  4. Add test coverage (#15)
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

piggito created an issue. See original summary.

piggito’s picture

StatusFileSize
new14.8 KB

Previous patch applied for 8.x-1.x branch on git repository but not for 8.x-1.x-dev then I'm attaching a new patch for this version.

Status: Needs review » Needs work

The last submitted patch, 2: allow_select_affected_forms-2.patch, failed testing. View results

piggito’s picture

StatusFileSize
new14.83 KB
new914 bytes

Fixing missing import for

Drupal\Component\Utility\Html
mroycroft’s picture

StatusFileSize
new16.13 KB
new13.14 KB

This is a really great and needed feature, thanks for the patch! I did take a look at these patches, and I've put together a new one that builds off the first one. Patches https://www.drupal.org/files/issues/2018-05-02/allow_select_affected_for... and https://www.drupal.org/files/issues/2018-05-02/allow_select_affected_for... didn't apply for me unfortunately.

Most of the changes are just fine tuning, but I also included the user login form under the list of general forms. This seemed like an appropriate addition to include. The weights are added in case someone wants to add more items to this list via form alter, this makes it easier to add new form IDs to a particular category of form.

I don't use webform module, so I have no feedback there. But I've made changes to other areas of the first patch where I thought improvements could be made.

Here's a patch and interdiff.

mroycroft’s picture

Status: Needs work » Needs review

The last submitted patch, 4: allow_select_affected_forms-3.patch, failed testing. View results

miiimooo’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
mroycroft’s picture

Is this tagged as needs re-roll for allow-select-affected-forms-2949540-5.patch ? As far as I can tell it applies cleanly, and there's been no new commits made since this patch was provided. Moving back to needs review unless there really is an issue applying allow-select-affected-forms-2949540-5.patch . I recognize some of the earlier patches didn't apply, but to me it doesn't make sense to ask to re-roll those earlier patches, as there was additional work needed on those patches anyways.

mroycroft’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
miiimooo’s picture

@mroycroft - my mistake - I misread the bot message

nikunjkotecha’s picture

Status: Needs review » Needs work

hi @piggito, @mroycroft,

Possible to split the work into two patches?
1. Add feature / admin form to allow configuring which forms client side validation should apply to.
2. Add new submodule for webform and add webform related customisation there.

I respect the decision by maintainers but see its high usage for webform we can go for sub-module which can be maintained by webform users. And I can work (when time permits) to fix webform related stuff there instead of disturbing the main module.

nikunjkotecha’s picture

Issue tags: +webform
kevin.dutra’s picture

Status: Needs work » Needs review
StatusFileSize
new13.73 KB
new2.92 KB

@nikunjkotecha
Here is the patch minus the webform specific stuff.

Were you thinking that the webform pieces should live in a submodule of Webform, or a submodule of Clientside Validation?

nikunjkotecha’s picture

Status: Needs review » Needs work

I would prefer a separate module itself, bridge between two where users of both can contribute and maintain.

sequence type boolean seems wrong here, IMO it should be string, can you confirm?

diff --git a/config/schema/clientside_validation.schema.yml b/config/schema/clientside_validation.schema.yml
new file mode 100644
index 0000000..7743168
--- /dev/null
+++ b/config/schema/clientside_validation.schema.yml
@@ -0,0 +1,12 @@
+clientside_validation.settings:
+  type: config_object
+  mapping:
+    form_settings:
+      type: sequence
+      label: 'A list of forms to configure for clientside validation'
+      sequence:
+        type: boolean
+        label: 'Whether the form is enabled for clientside validation'
+    enable_all_forms:
+      type: boolean
+      label: 'Setting to enable all forms for clientside validation'

Also, to make it more generic I would add checks on both form_id and base_form_id, many webform/commerce related forms would be difficult to cover with just form id.

Last thing, can you add some tests for this? TIA.

nikunjkotecha’s picture

Status: Needs work » Postponed
rahulrasgon’s picture

StatusFileSize
new16.16 KB

Rerolled #5 for 3x branch

l_vandamme’s picture

StatusFileSize
new7.98 KB

I rerolled the patch against the 3.0.0-rc4 version just to have another opinion on the functionality:

  • No more checkboxes per form, replaced by a text area for form ids
  • Better support for webform's clientside validation configuration by respecting the novalidate attribute
  • Moved settings form to admin/config/system/
nginex’s picture

Patch #18 works for me

saso.sotlar’s picture

StatusFileSize
new8.02 KB
new610 bytes

Updated patch from #18: fixes notice / warning that shows up in some cases.

nikunjkotecha’s picture

Status: Postponed » Needs work

Hi Laurens, Alex, Sašo and all involved here, below is how I would love to see we move forward to have these things merged.

  • Remove all the references of webform or any contrib module
  • Raise PR for just the changes required to facilitate webform related changes from other module (like the configuration form and all)
  • Create new contributed module for the bridge between webform and clientside_validation so it can be added for all those who need without increasing the scope of either clientside_validation or webform modules
nikunjkotecha’s picture

Version: 8.x-1.x-dev » 3.0.x-dev
themodularlab’s picture

FYI, I'm currently building a site on acquia that uses Site Studio and just discovered that clientside validation seems to be preventing site studio admin component forms from saving, submitting, etc. The patch on #20 actually solved my issues. I also have webform clientside validation submodule enabled and between the patch and that module, I'm able to use clientside validation on all my webforms but it no longer breaks site studio forms. I see there's still a debate on how to handle these changes but just offering a solid thumbs up for the most recent patch as well as hoping to see this feature in a future release. Thanks!

jzavrl’s picture

StatusFileSize
new8.05 KB
new1.51 KB

Updated the latest patch here as when you are using AJAX of Webforms, once the form is reloaded the #after_build is not in the $form array anymore and the if statements return an error and break the AJAX callback.

jwilson3’s picture

Title: Allow to select which forms are affected by clientside validation » Allow specific form ids for clientside validation
al0a’s picture

StatusFileSize
new2.09 KB

Rerolled the patch of #24 so it applies on the 4.0.x version.

al0a’s picture

StatusFileSize
new7.76 KB

Sorry, Previous patch didn't contain everything.

loze’s picture

Applied the patch to 4.x and it appears to be working as advertised.

One suggestion, I think it would be better if instead of a checkbox to enable on all forms it was radio buttons
[] Add to all forms except those listed
[] Add to only the forms listed

In my case there are only a few forms I want to disable it on, so listing every possible form I want it on for would be difficult, plus I don't want to have to update the list when new forms are added to the site.

xurizaemon’s picture

Issue summary: View changes

Copying NW tasks from #21 to ID.

xurizaemon’s picture

Issue summary: View changes
edmund.dunn’s picture

StatusFileSize
new7.59 KB

I rerolled this to move the menu link from config->system to config->user interface. Also had to move the setting.yml file into the config/install directory to prevent an error when installing the module.

This works well for our needs.

edmund.dunn’s picture

Status: Needs work » Needs review
edmund.dunn’s picture

Version: 3.0.x-dev » 4.0.x-dev
ludo.r’s picture

Patch #31 seems to work on our side (Using version 4.1.0).

I also agree with suggestion in #28, to have both options (white/black-list).

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

skyriter’s picture

I created a separate issue specific to exceptions, building off of the the most recent work done for this issue: https://www.drupal.org/project/clientside_validation/issues/3495738#comm...

skyriter’s picture

I should note that we have tested patch #31 and it appears to be working without issue.

skyriter’s picture

StatusFileSize
new9.43 KB

I have added the patch file, but even though this is working on my local and in our testing environment, I'm getting a PHPUnit error that I do not understand. If anyone could help with this, I'd appreciate it.

skyriter’s picture

StatusFileSize
new9.63 KB

Now that I've updated the config that gets installed, the tests are passing.

skyriter changed the visibility of the branch 3495738-form-exceptions to hidden.

skyriter’s picture

StatusFileSize
new10.15 KB

Adding the newest patch, after the issues identified by coderdan were resolved.

This patch removes any mention of webform.

j-barnes’s picture

StatusFileSize
new10.31 KB

Updated the latest patch to include a small change to allow for patterns similar to how config ignore works. We encountered a use case where enabling client-side validation for all webform submissions was necessary. However, manually adding hundreds of form IDs was impractical.

Example:

webform_submission_name_change_test_form
webform_submission_*
asherry’s picture

Status: Needs review » Needs work
StatusFileSize
new11.47 KB

Hi all. I'm late to the party and definitely not an authority on this project but we're having a major issue with this module breaking layout builder forms after setting the jquery validate library to trigger before ajax submit.

The latest code in this ticket (which I'm assuming is in #43) isn't completely working for us because it doesn't actually change the behavior of the jquery validation library.

I created a patch to get our site working temporarily but it really only accounts for our specific use case. Here is an overview of what's in the patch. I also included a few questions that might help me understand how to get to a real solution that fixes all use cases.

  1. It's not clear to me how this module is usable without enabling the jquery sub-module
  2. Given that, the jquery validation code completely ignores the form settings established in the base module
  3. The logic in clientside_validation_form_alter seems to be a bit confusing. It's not clear to me why we need to add the #after_build function and then remove it if novalidate is set rather than just initially checking for novalidate and skipping the rest of the logic
  4. I added a class to the form if the form id matches in one of the cases. I used that in clientside_validation_jquery/js/cv.jquery.validate.js which works for our use case but I'm sure isn't going to work for sub elements or other validation implementations that aren't jquery