Home › Forums › Classic DFFS › Check Unique Field before completing form.
- This topic has 2 replies, 2 voices, and was last updated 3 years, 1 month ago by Bryan Waldrop.
-
AuthorPosts
-
-
October 20, 2021 at 16:14 #34864
Can I add a save button in the new form that saves but does not close the new form?
I have a very long form with many fields to complete that also had a unique field (ID)(which is also the only required field). I would like to provide for the user to be able to “check” that they have not entered a duplicate for that unique field before continuing and find out there is an existing record at the end of rather lengthy process.
Can I add a button that saves after they enter data and does not close/leave the new form in this first unique field and effectively lets the user know there is an existing record for that ID before they continue with the rest of the form?
Or is there some other validation trick I can employee?
- This topic was modified 3 years, 1 month ago by Bryan Waldrop.
-
October 20, 2021 at 16:35 #34867
You can use the Misc tab Save and redirect functionality to save and redirect to EditForm, but I think a validation function will be better.
You can use this custom js to check that the selected value is unique:
function checkUniqueId(fin){ var res = spjs.utility.queryItems({ "listName": _spPageContextInfo.pageListId, "query": "<Where><Eq><FieldRef Name='"+fin+"' /><Value Type='Text'>"+getFieldValue(fin)+"</Value></Eq></Where>", "viewFields": ["ID"] }); if(res.count > 0){ spjs.modal.add({ "title": "Not unique", "html": "The value in the field " + spjs.dffs.fieldData[fin].disp + " is not unique, please correct and try again.", "ok": function (){ setFieldValue(fin, ""); } }); } }
Add this button in a HTML section below the ID field to let them validate the ID manually (replace YOUR_FIELD_NAME with the actual internal name of your field):
<input type="button" value="Verify that this ID is unique" onclick="checkUniqueId('YOUR_FIELD_NAME');return false;">
It could also be attached on “blur” of the field if you like an automated method – in that case you skip the button, but add this to your custom js below the checkUniqueId function:
jQuery("#dffs_YOUR_FIELD_NAME input[type=text]").on("blur", function(){ checkUniqueId("YOUR_FIELD_NAME"); });
Replace YOUR_FIELD_NAME with the actual internal name of your field.
Alexander
- This reply was modified 3 years, 1 month ago by Alexander Bautz.
-
October 20, 2021 at 16:55 #34869
Thank you so much as always! The on blur automated solution is much more elegant and very appreciated.
-
-
AuthorPosts
- You must be logged in to reply to this topic.