Link Rules Assistance

Forums Classic DFFS Link Rules Assistance

Tagged: 

Viewing 5 reply threads
  • Author
    Posts
    • #36749
      Jordan
      Participant

      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?

    • #36750
      Alexander Bautz
      Keymaster

      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

    • #36751
      Jordan
      Participant

      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 11 months, 3 weeks ago by Jordan.
    • #36753
      Alexander Bautz
      Keymaster

      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

    • #36772
      Jordan
      Participant

      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”.

    • #36777
      Alexander Bautz
      Keymaster

      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();
      
Viewing 5 reply threads
  • You must be logged in to reply to this topic.