SPRequireUnique problem with other validators

Apr 9, 2011 at 2:10 PM

I have used SPServices on MOSS 2007 for a custom new form, there is a problem: if another field on the custom form has a validator (a needed field, for example) if i compile the field for which i have used
SPRequireUnique and i don’t compile the other field i got the error for other field (the red label), then there is a js error “Unable to get value of the property ” on SPRequireUnique , so the unique validation does no more works and i can insert a duplicate value.
i use jquery 1.5 , spservices 0.6

Coordinator
Apr 10, 2011 at 11:50 AM

mistral61:

I've rarely seen people trying to add these functions to compiled code, though they ought to work. The difference is probably that the markup in the DOM is different than what would normally there because you've customized the form.

M.

Apr 10, 2011 at 2:32 PM
"Compiled code" ? i have created with SharePoint Designer 2007 an custom add form , then i have implemented this js code after the last  WebPartPages:DataFormWebPart  :
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js"></script>
<script type="text/javascript" src="jquery.SPServices-0.6.0.min.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
		$().SPServices.SPRequireUnique({
			columnStaticName: "Classification",
			duplicateAction: 1,
			ignoreCase: "false",
			initMsg: "Classification must be unique.",
			errMsg: "This classification already exists."
		});

});
</script>

Normally this code works , if i correctly insert every field and try to insert a duplicate value for "Classification" i get the red label with my message , but if i don't insert a  value on another (requested)  field there is the explained problem,after correct the other field then the unique validation does not work more and can be inserted a duplicate Classification.

The only workaround is to be "proactive" and use PreSaveAction wher eto control by hand ,with javascript , the other validations.

 

 

 

 

 

Coordinator
Apr 10, 2011 at 2:47 PM

You had said "compile the field", so I assumed compiled code. Sorry.

I'll need to try to reproduce this in my environment. Perhaps you've found a bug. So the issue is when you don't fill in a different required column than Classification, correct? What type of column is the other one?

BTW, I always put my script just below this line:

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

I find that it always works and it's also helpful to know that I can always look in exactly the same place in all of my pages.

M.

Apr 13, 2011 at 9:32 AM

Sorry for the long delay, i was busy.
Your code is found tipically in default.aspx of the site collection, my code is in a custom addnew form , where there is something as

asp:Content id="Content1" runat="Server" contentplaceholderid="PlaceHolderMain"

I have tried to move my js code under this line, but nothing is changed.
In my list there are these fields:
Classification , single line of text which should be unique in the list
Title,  single line of text which is requested (must not be empty)

The sequence is: i insert a valid value (not duplicated) in Classification , but i write nothing in Title , the ok button is active so i can click but i get the error (red label under the field) for the Title.
At this point i insert a value in Title , but i can correct the Classification and insert a value that already exists on another list item, the ok remains active (no error from the validator) so i can insert a new list item with a duplicate value for Classification.

Yes, i can use PreSaveAction and verify by javascript the validation on Title , not starting the aspx validators the validation for Classification works correctly , but to mix window.alerts with the red labels for errors is not the best approach.
R.

Coordinator
Apr 13, 2011 at 11:48 AM

I'm still having a bit of difficulty understanding the scenario. Of course you're using SPRequireUnique in a form, as that's the only place it would be useful.

Are you using the Title for something specific? If not, why not use the Title to contain the Classification value? That's how I would do it, and I know that SPRequireUnique would then work.

M.

Apr 13, 2011 at 12:07 PM

I need both, in every case this is only a sample: in my form there are other required fields, and there is the same problem.

R.

 

Coordinator
Apr 13, 2011 at 12:17 PM

Ok, let's consider this a bug, then. I'll add it to the Issue Tracker and try to get to it for the next release.

M.

Coordinator
Apr 13, 2011 at 12:17 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.