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.
Hi all,
Feature needed for my current project and seems to be interested for this module - conditions constructor. There is need to be able to build from GUI arbitrary complexity logical expression including NOT AND and OR operators.
Patch to be provided shortly
Comment | File | Size | Author |
---|---|---|---|
#2 | webform_conditional_conditions_constructor.patch | 50.5 KB | ogorun |
#2 | webform_conditional.zip | 24.5 KB | ogorun |
Comments
Comment #1
ogorun CreditAttribution: ogorun commentedSorry for previous invalid status. Status is changed to active
Comment #2
ogorun CreditAttribution: ogorun commentedHere is a patch for review with implemented feature.
I prepared jquery plugin le (logical expression) that includes $.le.expression class with API for expression building and evaluation, $.fn.leConstructor plugin component with GUI for conditions constructor and $.fn.leConditionalForm plugin component for client-side conditional form processing. This javascript was main work to get module work with complex expressions. After client-side build serialized expression is stored in hidden field representing one of component properties.
There are two more changes in patch that need to be discussed.
1. Since plugin works currently with operations =, >, <, >=, <=, 'starts from', 'ends with', 'contains','empty', 'one of' (and this set is customizable), I don't see sense to restrict trigger fields just to selects/radios. So I let any type of component except 'pagebreak' to be a trigger (but not select options that allow multiples)
2. There was preparation in code of module to functionality of optional mandatory fields - fields, that should be considered mandatory in case they are visible. I completed this functionality in following way. To avoid chains of expression evaluation on both client- and server-side, all evaluation is done only on client side and pass fields that need to be considered as mandatory in current situation through hidden field.
This variant is tested with module Webform in versions 2.6 and 2.9 currently
I'll be glad to hear any feedback
Comment #3
ogorun CreditAttribution: ogorun commentedComment #4
Marat CreditAttribution: Marat commentedI tried it with Webform 3 and got this error:
Fatal error: Call to undefined function webform_load_components() in /home/sites/all/modules/webform_conditional/webform_conditional.module on line 179
Comment #5
Marat CreditAttribution: Marat commentedI tested it with Webform 2.9, it works fantastic. It has so nice functions, thank you very much @ogorun!
Please keep going with this one, it is really awesome.
Comment #6
ogorun CreditAttribution: ogorun commentedThank you for feedback, Marat. I'll test things with Webform 3. It seams these version have incompatible API.
Comment #7
Marat CreditAttribution: Marat commentedI found it works with only the first component of webform; however, it does not work properly in the second component and so on.
What happens, the first choice of the dependent component (here is multiple selection) is hidden instead of the independent components. This occurs only in the later components.
Comment #8
ogorun CreditAttribution: ogorun commentedHi Marat,
Please give me more details about this problem with components order because I use this patch with differently placed components and didn't meet such situation. An as I could noticed work with inheritances of dependencies. The only thing I can notice now is that multiple selection is not supported (like in original webform_conditional module).
Please describe the situation you meet the problem.
Comment #9
Marat CreditAttribution: Marat commentedSorry @ogorun, I think I mixed up. I used numbers for the "Field Key", but when I changed to letters, it works well. Please accept my apologies for distracting you.
Comment #10
ogorun CreditAttribution: ogorun commentedSince Webform 3 already has own conditional fields engine and Webform Conditional module is on the way to be merged into it, it's more logical to speak about this feature as part of Webform module and not of Webform Conditional. So I submitted patch to Webform issue (see issue Merge Webform Conditional into Webform (support for same-page conditional fields)) and don't plan now to update patch for Webform Conditional module in order it to be able to work with Webform 3. This patch is considered for work with Webform 2 (if such solution is interesting for anybody).
So I revert status to 'needs review'
Comment #11
tedbowI have changed the setting module to add the "operator" field similar to the main Webform module. I think it is best to keep the settings as similar to the main Webform module as possible.