Home › Forums › Classic DFFS › Programmatically set field to “Required” based on multiple inputs
- This topic has 6 replies, 3 voices, and was last updated 9 years, 3 months ago by Alexander Bautz.
-
AuthorPosts
-
-
July 14, 2015 at 12:13 #7900
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(); -
July 14, 2015 at 12:17 #7901
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.
-
July 14, 2015 at 13:01 #7902
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. -
July 15, 2015 at 12:08 #7907
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.
-
July 16, 2015 at 16:17 #7920
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(); -
July 19, 2015 at 10:09 #7957
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{ -
July 25, 2015 at 08:26 #7976
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.