Inline Editing w/ SPRequireUnique

Jun 7, 2010 at 7:02 PM
This function simply rocks and it's actually the first one I've ever used. I know I should be using this library everyday, but in my defense, until now I haven't needed to use it. I feel like I have a valid request and if at all possible, could SPRequireUnique work with Inline Editing? I've exhausted my knowledge as to how to get it to work, but on Twitter there seem to be a lot of confidence in regards to this being possible. I'm using a single item DVWP and that's my only requirement. Thanks for your time, Matt B. @iOnline247
Coordinator
Jun 7, 2010 at 7:10 PM

What do you mean by a "single item DVWP"? Is it the only form on the page? Have you customized the form code much?  If you could paste the DOM you end up with here, it would be helpful.

M.

 

Jun 7, 2010 at 8:45 PM
sympmarc wrote:

What do you mean by a "single item DVWP"?

I have customized the page and have added 4 DVWP's.  There is only one that has Inline Editing capabilities though.  Here is the code that runs the page; I tried to add all of it, but it won't accept the message.

http://bit.ly/9fZN4M

Sorry the format sucks, I hope it helps...

 

Coordinator
Jun 7, 2010 at 8:51 PM

Since SPRequireUnique is running on page load -- actually (document).ready -- the form won't be in edit mode when it runs, right?

M.

Jun 7, 2010 at 9:27 PM

Well now, aren't you smarter than the average bear... That makes total sense...  I think I need to store the code in a .js file and make a call to it like the other .js files.  On the save action, should the code look like this?:

 

<a href="javascript: if(PreSaveAction()) {ddwrt:GenFireServerEvent('__commit')}">save</a>

 

I'm not too sure how I set this up.  From the looks of it, I should put my function call in the parenthesis after PreSaveAction.  So I'm thinking it should look like this:

<a href="javascript: if(PreSaveAction(SPRequireUniqueColumn)) {ddwrt:GenFireServerEvent('__commit')}">save</a>

Also what should my SPRequireUnique.js file look like?  Sorta new to javascript, extremely new rather...

Here's what I have:

<SCRIPT LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">
<!--
function SPRequireUniqueColumn()
   {
   	$().SPServices.SPRequireUnique({ 
 	columnStaticName: "Job_x2000_Number", 
 	duplicateAction: 1, 
	ignoreCase: "false", 
	initMsg: "This value must be unique.", 
	initMsgCSSClass: "ms-vb", 
	errMsg: "This job number must be unique.", 
	errMsgCSSClass: "ms-formvalidation", 
	completefunc: null 
	});
   }
//-->
</SCRIPT>

Does all of this look right?
Coordinator
Jun 7, 2010 at 9:34 PM

As I said on Twitter, SPRequireUnique can't go in the PreSaveAction (because at point it's too late).

It doesn't matter functionally if the script is inline or external. You'll need to fire SPRequireUnique when the form switches from display to edit so that the function has something to munch on.

No guarantee that it is going to work if you do the above, though.  Like I said, it's designed to work on the standard forms (and with some customization), but you're trying something different.

M.

Jun 7, 2010 at 9:42 PM

I don't think it's going to work then... and I'll tell you why.  I added a simple alert("jQuery Lib Loaded"); and put my code all back inline.  The code looks like this:

 

<script language="javascript" type="text/javascript" src="http://intranet:13000/sites/Test/PCP/jQueryLibrary/jQuery-latest-min.js"></script>

<script language="javascript" type="text/javascript" src="http://intranet:13000/sites/Test/PCP/jQueryLibrary/SPServices-latest-min.js"></script>  

<script language="javascript" type="text/javascript">

$(document).ready(function() {

  $().SPServices.SPRequireUnique({

   columnStaticName: "Title",

duplicateAction: 1,

ignoreCase: "false",

initMsg: "This value must be unique.",

initMsgCSSClass: "ms-vb",

errMsg: "This job number must be unique.",

errMsgCSSClass: "ms-formvalidation",

completefunc: null }); });

 

alert("jQuery Lib Loaded");

</script>

 

The alert fires when I click edit, but I don't get any feedback as expected with the RequireUnique function.  Well it was worth trying out.  Now that I have your library loaded, I have no excuse not to use it...

Coordinator
Jun 7, 2010 at 9:44 PM

Yeah, the DOM is likely to be structured differently on your form.  It's going to be possible to get it to work, but you'll have to debug it.\

M.

Jun 7, 2010 at 9:49 PM

Would that be something that could be identified and made a function?  Similar to all of the other functions you have or is that a volatile input?  I don't know how to debug the DOM as of this writing, but maybe sometime in the future...  For right now, I'll have to leave it up to the experts...

 

Thanks for all of your time today!

Matt

Coordinator
Jun 7, 2010 at 10:06 PM

The problem is that there's no way to predict how someone might customize a page. Providing functions wich work with the standard forms, even with some customization, covers the first probably 98% of the time. The other 2% is a total crap shoot.

M.

Jun 10, 2010 at 9:39 AM
Edited Jun 10, 2010 at 9:41 AM

Hi Team

the script is not working for me.

below is my implemention and screen shot

 $(document).ready(function() { 
$().SPServices.SPRequireUnique({
  columnStaticName: "Title",
  duplicateAction: 0,
  ignoreCase: "false",
  initMsg: "The RequestID must be unique.",
  errMsg: "This RequestID already exists."
 });
 });



I am getting all initmsg attached to all input controls in the page / my form is customized form.

Thanks

 

Coordinator
Jun 10, 2010 at 12:30 PM

pgopal:

I can't tell from what you posted what's going on.  Can you please start a new thread and post more details?

M.