Skip to content

Instantly share code, notes, and snippets.

@EmmanuelDemey
Created November 24, 2014 14:00
Show Gist options
  • Select an option

  • Save EmmanuelDemey/d5fb574a13cd6ca1b9ac to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelDemey/d5fb574a13cd6ca1b9ac to your computer and use it in GitHub Desktop.
Slide 143 - Using form validation methods
<form name="myForm">
<h3>Training complaint form</h3>
<!-- Show only if the complaint msg length > 5. -->
<alert type="error" data-ng-if="myForm.txtContent.$error.maxlength">
Complaint message must be five characters long or less!
</alert>
<!-- Name is required -->
Your name: <input type="text" name="inputName" ng-model="complaint.name" required/>
<!-- Correct mail format + required -->
Your mail: <input type="email" name="inputMail" ng-model="complaint.mail" required/>
<!-- Required + 5 characters max -->
Your complaint: <input type="text" name="txtContent" ng-model="complaint.content" required data-ng-maxlength="5" />
<!-- Disabled if the form has any error. -->
<button class="btn" ng-click="sendComplaint()">Send</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment