Home › Forums › Classic DFFS › Link Rules Assistance
Tagged: rules
- This topic has 5 replies, 2 voices, and was last updated 1 year, 8 months ago by Alexander Bautz.
-
AuthorPosts
-
-
May 1, 2023 at 21:48 #36749
Scenario: I have a tab, ID_00, with 2 true/false fields, Field A and Field B. I want a different tab, ID_01, to display only if BOTH fields are false.
I am getting caught up in the fact that there are 2 fields that must be false instead of just one. Note: I will eventually have 10-20 yes/no questions where all need to be False in order for the tab to display.
I am thinking I need a rule per field but I don’t know if a) that is right b) the logistics of setting it up (what do I select for the result of each rule? do I create a ‘parent’ rule to link them where the result is show tab ID_01?
-
May 1, 2023 at 21:56 #36750
Based on the number of fields that needs to be checked I think this is better solved with some custom js. If you can give me some more details on what you want to achieve I can show you how you can set up a custom js function to do this.
Alexander
-
May 1, 2023 at 22:12 #36751
I appreciate the quick response. I am working on a proof-of-concept for building a decision tree-like process. Certain true/false questions will trigger tab1 (aka Decision A) to display if marked true and others tab2 (Decision B).
I am good with the rules for any that are true but there is a scenario where if all questions are false then tab1 should display. Unfortunately, I can’t have tab1 display by default.
Thank you again.
- This reply was modified 1 year, 8 months ago by Jordan.
-
May 2, 2023 at 07:47 #36753
You can set up a rule that has the trigger “No trigger (must be triggered manually)” and in this rule set the tab as visible in the “Visible tabs” field.
Now add this to your custom js – changing the field internal names in the array “arrOfBoolean” and the name of the rule “IndexOrFriendlyNameOfRuleThatShowsTheTab” to match your fields and the name of your rule.
// Array of all field internal names for the boolean fields var arrOfBoolean = ["Boolean1", "Boolean2"]; // Add onchange arrOfBoolean.forEach(fin => { jQuery("#dffs_" + fin + " input:checkbox").on("change", function(){ onBooleanChange(); }); }); function onBooleanChange(){ var allFalse = true; arrOfBoolean.forEach(fin => { if(getFieldValue(fin)){ // If one of the fields are true allFalse = false; } }); // If all are false - call the rule that shows the tab if(allFalse){ spjs.dffs.triggerRule(["IndexOrFriendlyNameOfRuleThatShowsTheTab"]); }else{ // Reverse rule if all are not false spjs.dffs.triggerRule(["~IndexOrFriendlyNameOfRuleThatShowsTheTab"]); } } // Trigger on load onBooleanChange();
Let me know how this works out.
Alexander
-
May 3, 2023 at 21:36 #36772
Unfortunately there has to be a default value with the Boolean fields. I was trying to use radio buttons with no default to ‘force’ the user to answer all questions.
With your JS, is there a way to adjust the function that checks each field? All values of the radio buttons will be the same: “Yes”, “No”.
-
May 4, 2023 at 22:34 #36777
Try it like this:
// Array of all field internal names for the radio fields var arrOfRadioChoiceFields = ["radio1", "radio2"]; // Add onchange arrOfRadioChoiceFields.forEach(fin => { jQuery("#dffs_" + fin + " input:radio").on("change", function(){ onRadioChange(); }); }); function onRadioChange(){ var allFalse = true; arrOfRadioChoiceFields.forEach(fin => { if(getFieldValue(fin) === "Yes"){ // If one of the fields are true allFalse = false; } }); // If all are false - call the rule that shows the tab if(allFalse){ spjs.dffs.triggerRule(["IndexOrFriendlyNameOfRuleThatShowsTheTab"]); }else{ // Reverse rule if all are not false spjs.dffs.triggerRule(["~IndexOrFriendlyNameOfRuleThatShowsTheTab"]); } } // Trigger on load onRadioChange();
-
-
AuthorPosts
- You must be logged in to reply to this topic.