backbone.js - Webshims - Show invalid form fields on initial load -


(follow on questions placeholder hidden)

i'd form validate existing data when loaded. can't seem happen

  • i jquery.each of controls , call focus() , blur(), there better way this? tried call ctrl.checkvalidity(), wasn't defined yet. when was, still didn't mark controls.
  • i seem have timing issue too, while focus , blur() fire, ui not update. it's if webshims not loaded yet, though fires in $.webshims.ready event.
  • i tried call $('#form').submit(), doesn't fire events expected. way make happen include input type='submit'. how can pragmatically case form validation clicking submit button would?

here's jsfiddle demonstrates problem. when form loads, want invalid email marked such. if click add button marked then, not when loaded. why?

  • focus , blur in control cause marked.
  • but, clicking add (which runs same method ran when loaded). why work 2nd time, not when loaded?

    updatevalidation : function ()  { this.$el.find('[placeholder]').each(function (index, ctrl) {       var $ctrl = $(ctrl);     if( $ctrl.val() !== "" && (ctrl.checkvalidity && !ctrl.checkvalidity()) ) {         // alert('do validity check!');         $ctrl.focus();         $ctrl.blur();     } }); } 

i see in ff 17.0.5. problem worse in ie9, taking 2 or 3 clicks of add before fields show in error. however, errors on of js files i've liked 'due mime type mismatch'.

this has fact, trying reuse .user-error class, "shim" css4 :user-error , shouldn't triggered script. user-error scripts loaded after onload or user seems interact invalid from.

from point of view, shouldn't use user-error , instead create own class. can check validity using ':invalid' selector:

$(this)[ $(this).is(':invalid') ? 'addclass' : 'removeclass']('invalid-value'); 

simply write function similar code , bind them events change, input , on , call on start.

in case still want use user-error, following, not recommend:

$.webshims.polyfill('forms'); //force webshims load form-validation module possible $.webshims.loader.loadlist(['form-validation']); //wait until form-validation loaded $.webshims.ready('dom form-validation', function(){     $('input:invalid')         .filter(function(){             return !!$(this).val();         })         .trigger('refreshvalidityui')     ; }); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -