javascript - What are the benefits of using ANGULARJS form validation instead of jquery form validation plugin? -
this might weird question. starting use angularjs , have question on form validation using angularjs.
my question why use form validation using angularjs if can same using jquery form validation. last 4 years almost, there has been no forms not validate using jquery form validation plugin. want know benefits of using angular js form validation instead of tested jquery form validation
i think main benefit ability testing , ease of use. angular approaches form validation declaratively whereas more complex jquery validation done via javascript. angular validation falls in line way html5 elements should validated , believes validation constraints should declared in markup rather in code (which agree).
the biggest problem (in opinion) validation in angular while pratice decalare validation rules on element displays data don't believe practice have define validation messages in markup @ same time.
<form name="signupfrm" novalidate="novalidate"> <div classs="form-row"> <label>username:</label> <input name="username" ng-model="model.username" ng-minlength="3" ng-maxlength="10" required/> <div class="errors" ng-show="signupfrm.username.$dirty && signupfrm.username.$invalid"> <small class="error" ng-show="signupfrm.username.$error.required">please input username</small> <small class="error" ng-show="signupfrm.username.$error.minlength">please enter min length of 3</small> <small class="error" ng-show="signupfrm.username.$error.maxlength">please enter max length of 10</small> </div> </div>
on large application becomes unmanageable forcing logic markup never cannot tested.
however, still favour on jquery , have created angular module angular-auto-validate seeks rid of need defined messages in markup. takes view while declarative nature of angular form validation great way show error messages user (with expressions) leads more unmaintainable; code hence module moves reduce complexity in markup applying dynamic validation message.
you can find module here , angular blog post behind idea here
Comments
Post a Comment