Home › Forums › Classic DFFS › Issue with rule to set multi-choice field
- This topic has 3 replies, 3 voices, and was last updated 4 years, 5 months ago by Alexander Bautz.
-
AuthorPosts
-
-
February 19, 2018 at 02:48 #19916
Using DFFS Backend v4.3.38, spjs-utility version 1.319
I have rules that sets a value for a choice field using the “set field value” setting. Some of these rules do not work. Everything looks fine when setting up the rule, but when I run it, the wrong value is set. Debugging the rule shows the same behaviour as I see on the form. If I reload the DFFS backend, the “set field value” no longer has any value specified.
Other rules on the same form are setting the same field to the same value without problems. This issue is happening for the two people editing DFFS rules. Deleting and adding the “set field value” config doesn’t make any difference. Changing the option to specify my own value does work.
-
February 19, 2018 at 19:34 #19923
Thanks for the feedback, I have verified this bug and will fix it in the next release. What causes it is that when clicking a radio or checkbox in the set field value section for a choice column, the script executes before the input has actually been properly “checked” and fails to pick up the value and write it to a hidden text input. To work around this issue, you can click the desired value two times to ensure it is set, or you can drop this snippet in your custom js:
spjs.dffs.setFieldValInput = function (elm, id) { var val = []; setTimeout(function(){ jQspjs("#" + id + "_wrap").find("input").each(function () { if (jQspjs(this).prop("checked")) { val.push(jQspjs(this).val()); } }); jQspjs(elm).parents("table:first").find(".dffs-setfield-input").val(val.join("|")); },100); };
Alexander
-
June 2, 2020 at 12:14 #30401
Hi Alex,
I am facing problem with triggering rules on multi-choice checkbox field using javascript.
Here is the scenario.
I have choice field, with choices like Software, Hardware and others.
I have set rules for each of them using DFFS forms. So when I check “Software” choice, the dffs forms open “ShowSoftwareSection”, When I check Hardware choice, it open ShowHardware section and when I check the Others choice, it open “ShowOthersSection”. All the above rules works fine when I do these activities manually.
The problem start when I try to load the multi-choice checkbox control dynamically using javascript.
On button click, if my script brings 2 values in array i.e. Software and others. I am using SetValueField(“controlName”,”Software,Others”) function to select the checkboxes and trigger their respective rules to open the sections.
Both options get selected on multi-choice control, but only first option’s rule gets triggered and it shows only first section.
Any help would be appreciated.
Thanks & Regards
Gangs -
June 2, 2020 at 14:31 #30406
Could you please try adding the snippet below in your Custom JS for this form to see if it fixes the issue?
spjs.utility.setFieldValue_SPFieldMultiChoice = function (a) { var f = jQspjs("#dffs_" + a.fin), t, currVal = String(spjs.utility.getFieldValue({ "fin": a.fin })), allOptTracker = {}, fillInArr = []; if (currVal !== String(a.newVal)) { if (!jQspjs.isArray(a.newVal)) { a.newVal = a.newVal.split(','); } jQspjs("#dffs_" + a.fin).find('input:checkbox').each(function () { t = jQspjs(this).next().text(); allOptTracker[t] = true; if (jQspjs.inArray(t, a.newVal) > -1) { if (!jQspjs(this).prop('checked')) { jQspjs(this).trigger("click"); } } else { if (jQspjs(this).prop('checked')) { jQspjs(this).trigger("click"); } } }); // Check fill-in jQspjs.each(a.newVal, function (i, val) { if (allOptTracker[val] === undefined) { fillInArr.push(val); } }); if (fillInArr.length > 0 && f.find('input:text').length > 0) { if (fillInArr[0] !== "") { f.find('input:checkbox:last').prop("checked", true); } else { f.find('input:checkbox:last').prop("checked", false); } f.find('input:text').val(fillInArr.join(", ")).trigger("change"); } spjs.utility.updateReadonlyValue(a, true); } };
Call it like you already did, but use an array format for the multiple options like this:
setValueField("controlName",["Software","Others"]);
Let me know if this fixed the problem.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.