Page 1 of 1
list item validation
Posted: Tue Oct 29, 2013 1:02 pm
by Bob Fludder
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
list item validation
Posted: Tue Oct 29, 2013 3:11 pm
by maxkatz
In case of error you want to stay on the same page? How do you validate entries?
list item validation
Posted: Tue Oct 29, 2013 4:23 pm
by Bob Fludder
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.
list item validation
Posted: Tue Oct 29, 2013 7:41 pm
by Maryna Brodina
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
list item validation
Posted: Tue Oct 29, 2013 8:55 pm
by Bob Fludder
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.
list item validation
Posted: Tue Oct 29, 2013 8:57 pm
by Bob Fludder
Oh forgot. Maryna. Thanks for that tip. It will solve a different issue when the page first displays.
list item validation
Posted: Tue Oct 29, 2013 9:46 pm
by Bob Fludder
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?
list item validation
Posted: Tue Oct 29, 2013 10:18 pm
by Maryna Brodina
$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