Home › Forums › Classic DFFS › Rule Validation
- This topic has 5 replies, 3 voices, and was last updated 8 years, 11 months ago by Alexander Bautz.
-
AuthorPosts
-
-
November 17, 2015 at 17:59 #9345
I have a function that adds another Save button at the bottom of the form that states “Complete & Send”, which changes a field in the form from “In Progress” to “Completed” (I will insert the function below). I am looking to add to this function that it verifies a certain Rule (with Index 2) is True before it actually saves. This will only go on the New Form. Currently I have tried to create a Rule where If “FinalSave” = Completed, then require some columns, but apparently the function that changes this field value to Completed is run after the form is saved and not before.
Functions are here:
(function(){ var b = [""]; b.push("<td class='ms-toolbar' nowrap='nowrap'>"); b.push("<input type='button' class='ms-ButtonHeightWidth' value='Complete & Send' onclick='finalSave();' />"); b.push("</td>"); b.push("<td class='ms-separator'> </td>"); $("input[id$=diidIOSaveItem]:last").parents("table:first").parents("td:first").before(b.join("")); })(); function finalSave(){ setFieldValue("FinalSave","Completed"); $("input[id$=diidIOSaveItem]:last").click(); }
-
November 17, 2015 at 23:44 #9348
Hi,
You can check the state of a rule by using this variable:var rStat = spjs.dffs.data.ruleIndexObj[IndexOrFriendlyNameOfRule]; //rStat will be true or false
Alexander
-
November 24, 2015 at 17:48 #9396
Got it working, thank you!
-
November 27, 2015 at 14:44 #9419
Kyle,
Your solution is great. I have a similar situation and would like to use your idea but have a question. If the user clicks the new Complete & Send button but errors catch it and they want to go back to the default save (without completing), how would I force the regular save button to toggle the value of the FinalSave field back to the “off” value (not completed…)?
Robyn -
November 30, 2015 at 20:18 #9434
It appears that there may be a bug in the DFFS solution. (I will add my code below). What I am seeing is, when the user clicks “Complete & Send”, and it changes the field value to “Completed” and runs the rule validation. If not all required fields are completed, there is an alert stating “Additional Fields are Required”, and then it changes the field back to “In Progress”.
The user should then be able to continue completing the form and be allowed to either “Save” or “Complete & Send”. If a normal “Save” is clicked, the rule validation should not apply because the field is still marked as “In Progress”. However, the rule is still being applied and requiring all fields that are listed within the rule. How can the rule be reversed after it has been applied?I have tried to create an additional rule that explicitly states the fields are Optional, but that still has not worked.
(function(){ var b = [""]; b.push("<td class='ms-toolbar' nowrap='nowrap'>"); b.push("<input type='button' class='ms-ButtonHeightWidth' value='Complete & Send' onclick='finalSave();' />"); b.push("</td>"); b.push("<td class='ms-separator'> </td>"); $("input[id$=diidIOSaveItem]:last").parents("table:first").parents("td:first").before(b.join("")); })(); function finalSave(){ setFieldValue("FinalSave","Completed"); var rStat = spjs.dffs.data.ruleIndexObj[1]; if (rStat == true){ $("input[id$=diidIOSaveItem]:last").click(); }else{ alert("There Are Additional Fields That Are Required"); $('[id$="FinalSave"] span input:checked').click() setFieldValue("FinalSave","In Progress"); } }
-
December 3, 2015 at 09:11 #9465
Hi,
Sorry for the delay.This is caused by the rule not being updated when you manually set the new value in the “FinalSave” field. This is *unfortunately* not a bug as the “spjs.dffs.data.ruleIndexObj” are only updated when the rules are validated on form load or when the rule itself is triggered.
What is the “trigger” in the rule you check in spjs.dffs.data.ruleIndexObj[1]? – if it is the “FinalSave” field you look at to see if it is “Completed”, you could use a snippet like this instead:
var rStat = getFieldValue("FinalSave") === "Completed"; //rStat will now be true if the FinalSave field is Completed.
Hope this helps,
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.