SPRequireUnique: When does it fire?

Oct 15, 2013 at 12:44 AM
In a similar vein to a couple of other forum posters, I am currently having problems with getting SPRequireUnique to work. (I am using SP Online - v15 (SP 2013))

In an attempt to debug my intended new item form, I have created a separate proof of concept list and tacked the following code into the page
            columnStaticName: "Title",
            duplicateAction: 1,
            ignoreCase: false,
            initMsg: "!!!",
            initMsgCSSClass: "ms-vb",
            errMsg: "This employee already has a record for the selected Skill and Proficiency Level.",
            errMsgCSSClass: "ms-formvalidation",
            showDupes: true,
            completefunc: function(){
                console.log("Require Unique run");
});//end ready
It seems everything is loading correctly as I am seeing the 'initMsg' text below my input field and my console message is being output, but my input just doesn't fail the validation test.

Taking a look at the underlying code, it appears the validation should be triggered when my 'Title' field loses focus but to no avail.

I have tested this both with and without the native SP column setting for requiring unique values and neither setting makes a difference to this function, although the native functionality does trap the duplicate value.

It seems that those who have resolved their issues with this function have done so more by luck than judgement, so any pointers would be gratefully received!
Oct 15, 2013 at 9:33 AM
So basically, when you do this, the OK button is never "disabled"? That's what should happen if you have in your case a Title that exactly matches an existing Title. The main issues I see here is that it may be that your OK button is not correctly identified so it can't be disabled. This may require looking at the code and comparing what the function is looking for versus what you actually have. I have seen this happen on pages where the OK button was modified. Just a thought!

Oct 15, 2013 at 3:30 PM
Can you step through the code and see whether the test is working correctly?

Oct 28, 2013 at 10:52 PM
Bit of a delay in replying as I been busy loving SharePoint in a few other ways :)

So, I've retried this function and have satisfied myself that the SPRequireUnique function runs through on the page load (checked by adding a console.log line to the completefunc option) and I get my initial message appearing under my Title field (I have checked this is a 'single line of text' field type). Checking the underlying markup I see the function is adding the expected id, i.e.
<span id="SPRequireUniqueTitle" class="ms-vb">

    Hey!  This must be unique!

The button references seem to be sound, i.e. the Save button still has a value of 'Save', so, seemingly all well and good.

So then I enter a value into the Title field, but there seems to be no further validation/action on either the blur or change events. Neither the errMsg or showDupes options take effect, no buttons are disabled (although I can live with that) and the only time duplicates are prevented is if I enforce the OOTB unique items option against the list column.

As a result I am confused! Am I initiating the function correctly and at the correct time and place within the script? I'm not going to rule out a 'fat fingers' typo/error somewhere, but given its a simple script on a one column list, am not sure where else I could go wrong.
Oct 29, 2013 at 3:24 AM
I just dropped your code above into a form in my test WSS 3.0 environment and it works exactly as it should (though your messages don't make any sense on my Regions list!). SharePoint 2010 (Office365) ditto.

I'm in the midst of upgrading my Office365 instance to 2013 (I just got upgraded!) and so I don't have an easy test list. However, in 2010, the Save button in the ribbon is NOT deactivated, just the one in the form. Might this be what you are seeing?

Oct 29, 2013 at 7:07 AM
Thanks for taking a look Marc.

I'm fairly ambivalent about the form buttons as I already have some code to take care of those. Although I acknowledge the ribbon button will not be affected, I am not seeing any disabling of the 'form' Save button. What I am really after is the error message and duplicates link to appear which steadfastly refuses to do so!

Getting this code working is a pre-cursor to my having a hack around at a local version of the source code to enable me to prevent duplicates in multiple columns on the same form/list. I figured I should get a single column reference working first before attempting anything else.

Unfortunately I no longer have a 2010 instance of SP Online to perform a comparative test on, so would very much appreciate it if you could rerun the same tests against the O365 2013 instance as and when you have the opportunity.

Thanks again for your assistance.