?
Solved

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

Posted on 2011-09-21
4
Medium Priority
?
986 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 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:Gurvinder Pal Singh
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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 …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 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