Solved

Need to override jqGrid behavior when checking data-val-unique

Posted on 2011-09-21
4
969 Views
Last Modified: 2012-05-12
I have a grid which uses the data-val-unique attribute of jqGrid to ensure that duplicates aren ot allowed. But the way it handle the comparison is killing performance.

Let's say the user sets a barcode value, jqGrid will instruct all other barcodes to compare themselves with the new code. It's loading the error image file for each as it does. The delay grows with each new addition and we are not able to support more than a dozen barcodes, yet we need to support hundreds. So I need to change the default behavior.

I'd like to call a function when there are duplicates, and only then, have jqGrid use the default error handling for duplicates.

I searched my solution for data-val-unique and found that in the file:

jquery.validator-extensions.js

there's a function which starts with:
$.validator.addMethod('unique', function(value, element, param) {

Can I override this function? How? I would not want to add code to a file from jquery.

Also, any suggestions for writing the function so that it only gets called when there are duplicates found?

Thanks.

0
Comment
Question by:newbieweb
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36578130
won't it be better to use associative arrays (just like maps in java) to see if the value already exist or not

var obj = new Array();

obj["1"] = "1";

so later if you want to check if value 1 is already inserted or not, then just check

if (obj["1"] != null && obj["1"] != undefined)
{
  //value already exists
}
0
 

Author Comment

by:newbieweb
ID: 36578150
Yes, that's a good idea. But I do not want to totally override the duplicates checking built into jQuery (at least I dont think I do). I made a related post where I am trying to override the keyup function, where I could do a check as you'd described, but make the function fit into a fluent API, as the keyup function does.

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27321409.html

I can inject the function which then kicks off the jquery validation, the way keyup kicks it off. But searching for dups with every keystroke if killing performance. I'd rather only kick off the jquery validation code once I already know there's a duplicate.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36578157
i have responded to that question by suggesting you to unbind the onkeyup event and report what happens
0
 

Author Closing Comment

by:newbieweb
ID: 36578252
I was thinking the same thing. BUT, interestingly, once I unbinded it, there was no need for my own validation test. Cool.  Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question