javascript - How to focus invalid element by DOM position from the array of Elements? -
i doing validation. in validation wherever element not valid, pushing array.
while user click on submit button, focus on element not it's array position. instead dom
position.
the issue because, server sending id
front end. while send id
, not form element order.
any idea please? simply, sort pushed element it's dom
position focus...
here focus approach:
this.validate = function () { $.each(this.elements, function (i,elem) { var element = $(elem); var prop = string(element.get(0).type).touppercase(); var result = that.validateone({"prop":prop,"elem":element}); }); if(that.validateresut.length) that.validateresut[0].focus(); //it focusing last element or mid time.. focus dom position }
thanks in advance.
you can try code sorting. later can append accordingly:
obj.sort(positionsort); //call function passing array of elements. function positionsort(a, b) { var = $('#' + a).position().top; var b = $('#' + b).position().top; return ((a < b) ? -1 : ((a > b) ? 1 : 0)); }
demo: http://jsfiddle.net/lotusgodkk/w2528/3/
see console result.
Comments
Post a Comment