Programmatically set field to “Required” based on multiple inputs

Home Forums Classic DFFS Programmatically set field to “Required” based on multiple inputs

Viewing 6 reply threads
  • Author
    Posts
    • #7900
      Drew Heggie
      Participant

        Hi Alex,
        I’m new to javascript so any assistance would be welcomed.

        I have a Form and based on the inputs from several fields I need to set a field to Mandatory (Required). The logic is If any response to “FX” OR “Rates” equals “Derivatives” then set the field “Legal Trading Docs” to Required.
        I seem to be failing on the syntax that sets the field to required.

        I’ve searched the forums and have got as far as:-
        // Onclick
        $(“FX, Rates”).find(“input:checkbox”).bind(“click”,function(){
        customRequiredField();
        });
        function customRequiredField(){
        var a = getFieldValue(“FX”);
        var b = getFieldValue(“Rates”);
        if((a==”Derivatives”)||(b==”Derivatives”)){
        document.getElementById(“Legal Trading Docs”).required = true;
        }else{
        document.getElementById(“Legal Trading Docs”).required = true;
        }
        }
        // On load
        customRequiredField();

      • #7901
        JGMcLoughlin
        Participant

          Drew,

          Have you tried using rules to achieve what you want? You can set a field to being required in a rule, so this might work. I have just spent days trying to do something clever in JavaScript only to discover I could have used a series of rules to achieve the same ends.

        • #7902
          Drew Heggie
          Participant

            Hi,
            Thanks for your reply.
            Yes I’ve been using rules throughout but I need to ensure that when a user goes back and un-checks an enrty that the Required field remains unchanged (at the moment the rules work fine until a user steps back a question – then the rule activates on that question and re-sets the Required fiekd to optional). I just need a function that checks the values of the other question responses to ensure the “Required” state remains if we still have a “Derivatives” selected.

          • #7907
            Drew Heggie
            Participant

              Hi,
              I’ve been doing a bit more digging on this and the solution proposed here
              Almost covers my situation. All I need guidance on is changing the Yes/No check box (check) to activate based on the value selected from a choice (in my case the choice would be “Derivatives”).

              Any assistance would be very welcome. Thanks in advance.

            • #7920
              Drew Heggie
              Participant

                Solved:
                using a combination of a couple of solutions posted by Alex on other issues I came up with the following:-

                $(“Field_01”, “Field_02″,”Field_03″,”Field_04″,”Field_05”).find(“input:checkbox”).bind(“click”,function(){
                customSetRequired();
                });

                function customSetRequired(){

                var a = String(getFieldValue(“Field_01”));
                var b = String(getFieldValue(“Field_02”));
                var c = String(getFieldValue(“Field_03”));
                var d = String(getFieldValue(“Field_04”));
                var e = String(getFieldValue(“Field_05”));

                var aa = a.indexOf(“Derivative”);
                var bb = b.indexOf(“Derivative”);
                var cc = c.indexOf(“Derivative”);
                var dd = d.indexOf(“Derivative”);
                var ee = e.indexOf(“Derivative”);

                if(aa>=0||bb>=0||cc>=0||dd>=0||ee>=0){
                spjs.dffs.flag_Mandatory([“Internal_Name_01”]);
                spjs.dffs.flag_Mandatory([“Internal_Name_02”]);
                spjs.dffs.flag_Mandatory([“Internal_Name_04”]);
                spjs.dffs.flag_Mandatory([“Internal_Name_04”]);
                }else{
                spjs.dffs.clear_Mandatory([“Internal_Name_01”]);
                spjs.dffs.clear_Mandatory([“Internal_Name_02”]);
                spjs.dffs.clear_Mandatory([“Internal_Name_03”]);
                spjs.dffs.clear_Mandatory([“Internal_Name_04”]);
                }
                }

                // On load
                customSetRequired();

              • #7957
                Drew Heggie
                Participant

                  Correction (Typo)

                  spjs.dffs.flag_Mandatory([“Internal_Name_01″]);
                  spjs.dffs.flag_Mandatory([“Internal_Name_02″]);
                  spjs.dffs.flag_Mandatory([“Internal_Name_03″]);
                  spjs.dffs.flag_Mandatory([“Internal_Name_04″]);
                  }else{

                • #7976
                  Alexander Bautz
                  Keymaster

                    Hi,
                    I’m glad you figured it out – I have a hard time following up all emails and forum posts so there will unfortunately be some time delay on my answers.

                    Alexander

                Viewing 6 reply threads
                • You must be logged in to reply to this topic.