[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-09-21
4
Medium Priority
?
1,000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…
Suggested Courses

649 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