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.
It would be great if you could add drag&drop-functionality to the created rules, so site builders could change the order of them being processed (and by that changing the output-order of messages to the user).
Comment | File | Size | Author |
---|---|---|---|
#5 | webform_validation-rules-order-1290218-5.patch | 9.2 KB | jfrederick |
#4 | webform_validation-rules-order-1290218-4.patch | 9.72 KB | jfrederick |
#1 | webform_validation-rules-order-1290218-1.patch | 9.43 KB | jfrederick |
Comments
Comment #1
jfrederick CreditAttribution: jfrederick commentedSee attached patch.
This patch adds a weight to validation rules. It replaces the validation rules admin interface with a form and a corresponding theme function, which formats the form as a drag and drop table.
When the validators are run, they are run in the order of their weight, as set in the drag and drop table. If you do not re-order the validators, their default weights are 0. If validation weights are equal, they are run in the order of ruleid DESC, just as they were in the past.
My main use case for this is to have conditional validation. I have one validator that I want to only run if all other validation has passed. Now, by placing this validator last, and checking form_get_errors(), I should be able to do this. Relates to How to create a conditional/dependent validator which is only triggered when all others validate
Disclaimer: The patch includes a schema update that adds a 'weight' field to the webform_validation_rule table. To run the schema update, run update.php or drush updb. Naturally, this update hook (7002) may interfere with the sequence of update hooks that may be introduced in the module henceforth. I still felt it best to move forward with more regular update hook numbering.
Please help fix up any mistakes in the patch, thanks!!
Comment #2
Liam MorlandThanks for the patch. I will review it when I have time. If others can give it a try, that would be appreciated.
Comment #3
Liam MorlandThanks very much for the patch. I think this is a good feature to have. A few comments:
Thanks again.
Comment #4
jfrederick CreditAttribution: jfrederick commentedThanks for the suggestions, they were extremely helpful.
Attached is an updated patch. It fixes 4 out of 5 of the issues you raised, simply excluding the separation of the patch into two separate patches. The reason that is problematic is the conversion of the admin interface to a theme function is heavily tied to displaying the admin interface as a form. But without the new weight field, there is no reason to have the admin interface be a form; there would be nothing to submit.
But let me know what you think.
Comment #5
jfrederick CreditAttribution: jfrederick commentedHeh, I included a stray dpm() in that patch. Removed in attachment.
Comment #6
Liam MorlandThanks very much.
http://drupalcode.org/project/webform_validation.git/commitdiff/5245ebd
http://drupalcode.org/project/webform_validation.git/commitdiff/df9eab9
Comment #7
Liam MorlandComment #8
Liam MorlandDrupal 6 is no longer supported.