php - minlength doesn't work with jquery validation -


i using jquery validation in zend 2. other validation types working except minlength.
here form code:

    $this->add(array(         'name' => 'usr_name',          'attributes' => array(             'type'  => 'text',             'id' => 'firstname',             'class'  => 'form-control',          // jquery validation rules:             'required'  => 'true',             'minlength'  => '2',             'maxlength'  => '20',         ),         'options' => array(             'label' => 'name',         ),     )); 

here js code:

 $('.form-validation').each(function () {      $(this).validate({       errorelement: "span",     errorclass: "help-block",         highlight: function(element) {         $(element).closest('.control-group').removeclass('success').addclass('error');         $(element).attr('style', "border-radius: 5px; border:#ff0000 1px solid;");     },     unhighlight: function(element) {         $(element).addclass('valid').closest('.control-group').removeclass('error').addclass('success');         $(element).attr('style', "border-radius: 4px; border:1px solid #ccc;");     },     errorplacement: function (error, element) {         $(error).attr('style', "color: #ff0000;");         if ( element.prop('type') === 'checkbox') {             error.insertafter(element.parent());         } else {             error.insertafter(element);         }     }    });  }); 

update :
html generated:

<input name="usr_name" type="text" required="required" maxlength="20" id="firstname" class="form-control" value="" aria-required="true"> 

look @ this:

strange, how can possible!

i found following article.

which strange how zf2 people consider logic!!

so ugly workaround injected minlength attribute in needed elements in following way:

 $('.minlength').each(function () {      $(this).attr("minlength", "8");  }); 

where minlength class added optionally needed elements give jquery opportunity work on them properly!


Comments

Popular posts from this blog

My HTML document is not linking to my CSS stylesheet properly -

php array slice every 2th rule -

node.js - Sending sockets to client side, Error: Converting circular structure to JSON -