Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

list item validation

I have a list box and am validating each item in it. Is there a way of staying on an item (ie giving it focus again)? At the moment when the user tabs to the next row, even if there is an error the cursor has moved to that next row (there is only 1 input field per row but does have some other text next to it). I'm currently using the blur event but was using on changed. Any ideas - your help would be appreciated as sometimes me and javascript don't exactly see eye to eye.

Thanks

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

list item validation

In case of error you want to stay on the same page? How do you validate entries?

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

list item validation

Done with some javascript on the bkur rvent. Not ssme page. Ssme input field. Have a list of ssy 10 items. The 3rd is wrong. Want the input (focus I guess) to stay at the 3rd item and not go to the 4th.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

list item validation

Hello!
1) Give all inputs you want to validate standard name. For example all of them should start with mobiletextinput (mobiletextinput_1, mobiletextinput_2, etc.)
2) On page Load run the following code:
pre$("[name^=mobiletextinput]").off().on("blur", function(){
var $this = $(this);
if (!$this.val()) { //here should be your real validation. instead of just "not empty" check
$this.focus();
}
})/pre

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

list item validation

Hi guys. Small misunderstanding. I'm validating what the user has just input and am trying to re-position at the field they just left. Thry are entering stocktake counts. After entering the count for the first item they go to enter the second. I'm checking the count on the first item as thry leave to enter the second. Just want to go back to the previous item because that was the one in error. All the items are on 1 line each.

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

list item validation

Oh forgot. Maryna. Thanks for that tip. It will solve a different issue when the page first displays.

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

list item validation

Have an idea. If I save $this in local storage when the field has focus. Can I then use that after my validation to give focus to the field I saved in local storage?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

list item validation

$this you can't store in localStorage variable (because in localStorage you can store strings only and $this is an object). But you can save $this object id prelocalStorage.setItem("savedId", $this.prop("id"));/pre
and use it to set the focus pre$("#" + localStorage.getItem("savedId")).focus();/pre

Return to “Issues”