0

I am doing site, which will help people to collect their water meters readings. At the moment I am doing input form for adding current month readings.

Browser is checking data when user input it, not on/after form sending (via jquery). For example, user inputted 123 and pressed d after. After he pressed d error will appear near input field etc... So field is validating on keyup action

I am thinking about adding test, that will be passed if user inputted value, that is not lesser then previous month (or not previous month, just last inputted) value.

So imagine: Last month meter value was 250. Current 255. Input field is blank. User staring print. He pressing 2 (inputted value is 2 now). Remember that value is being tested on key up? jQuery will start test and will return error because 2 (current value in field) < 250 (last month meter value). After that he pressing 5 (inputted value is 25 now). 25 < 250, so jquery will still show error, that value, user inputting is invalid. After that he printing 5 again (now value inputted is 255). 255 not < then 250, so error message/block will disappear.

So the question is such: is it correct to show error on keyup for this test (checking if inputted value is less then last month value)? I think it is not rly correct, because some users are very newb to pc's and this message can scare them or idk :)))
Is it okay or should I find a way to test this only on onblur action (remove focus from field)? But will it be too late to show error message (I mean usability ofc)? I am checking inputs when ppl input their data because of better usability (so ppl know about his mistake on input stage, not after sending form).

Maybe there are another suggestion?

Sparky
  • 98,165
  • 25
  • 199
  • 285
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87
  • Questions asking us for opinions are not allowed on StackOverflow. It's best to present very specific questions rather than "what is best?" or presenting various hypothetical scenarios. – Sparky Mar 22 '14 at 00:40
  • If you're using jQuery Validate, none of the validation would occur until after the initial "submit" event. Then `onkeyup` and `onblur` come into play. There are ways to disable or modify these events but I cannot post a specific answer to such a generic question. – Sparky Mar 22 '14 at 00:41

2 Answers2

0

Add 2 events, one onkeyup and one onblur? The onkeyup can check for incorrect characters and the onblur can compare the input value to last month

garethb
  • 3,951
  • 6
  • 32
  • 52
0

Add a timeout to the keyup, this is a possible duplicate of this same issue:

How to trigger an onkeyup event that's delayed until a user pauses their typing?

Community
  • 1
  • 1
ml242
  • 109
  • 13
  • May be it is nice suggestion. Found this issue exactly for this plugin [link](https://github.com/jzaefferer/jquery-validation/issues/466), but it is not still done. Any suggestion how I can use onkeyup delay on my code? Check [this jsFiddle](http://jsfiddle.net/FvAs5/). There are no remote test, but can you help with `digits` for example? Thank you. – Sharikov Vladislav Mar 18 '14 at 23:28
  • Can you post again in the jsFiddle? I thought it was validating but it is not now. I'm hoping to wrap it in something like this: var delay=2500 // 2.5 seconds setTimeout(function(){ //your code to be executed after 2.5 seconds }, delay) – ml242 Mar 18 '14 at 23:59
  • What do u mean? This is jsFiddle : http://jsfiddle.net/95kgu/ . It is validating okay atm. – Sharikov Vladislav Mar 19 '14 at 00:01
  • Simply linking to another SO answer is not an acceptable answer. I'll retract my down-vote if you'll edit your answer to be fully "self-contained". – Sparky Mar 22 '14 at 00:36