Check Unique Field before completing form.

Forums Classic DFFS Check Unique Field before completing form.

Viewing 2 reply threads
  • Author
    • #34864
      Bryan Waldrop

      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 2 years, 8 months ago by Bryan Waldrop.
    • #34867
      Alexander Bautz

      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){
                  "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(){

      Replace YOUR_FIELD_NAME with the actual internal name of your field.


    • #34869
      Bryan Waldrop

      Thank you so much as always! The on blur automated solution is much more elegant and very appreciated.

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