angularjs additional form validation rules (not input field validation) -


There is an angular way of adding verification rules to a form, which is related to a single not Input field, but together on multiple field values?

Example:

  • Check that at least one x check box has been checked
  • Check if Yoga
  • < Li>

    It would be great if errors can be shown with ng-message I am using angular 1.3.10 I am

There is no built-in functionality, but it requires little effort.

ng-message does not depend on something special; it only requires an object whose keys can be referenced by ng-message The easy solution submit will be to hook up in the event (which you probably do anyway) and will run additional verification.

  & lt; Form ng-submit = "post ()" Name = "myForm" & gt; & Lt; Input type = "checkbox" name = "one" ng-model = "a" /> & Lt; Input type = "checkbox" name = "two" ng-model = "two" /> & Lt; Input type = "submit" / & gt; & Lt; Div ng-messages = "formErrors" & gt; & Lt; P ng-message = "lot" & gt; Please, check only one checkbox & lt; / P & gt; & Lt; P ng-message = "required" & gt; Please check the checkbox & lt; / P & gt; & Lt; / Div & gt; & Lt; / Form & gt;  formErrors : 

$ scope.post

object when submitting the post () = Function () {... var hasErrors = false; $ Scope.formErrors = {}; If ($ scope.one & amp; amp; $ scope.two) {$ scope.formErrors.tooMany = isers = true; } If (! $ Scope.one & $ $ Scope.two) {$ scope.formErrors.required is Errors = true; } If (Harris) {return; }}


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -