Solved

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

Posted on 2011-09-21
4
965 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

803 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