I'm getting neither a value emitted by the template fragment nor functioning validation. My Jade template:
doctype html
html(lang='en', ng-app="Validate")
head
script(src='#{cdn_path}/angular.js/1.3.11/angular.js')
script(src='#{cdn_path}/angular.js/1.3.11/angular-messages.js')
script.
angular.module('Validate', ['ngMessages']);
body
.container
form(method="POST", action="/apply", name="myform", novalidate="")
pre myform.name.$error = {{ myform.name.$error }}
input.form-control(name="name", required="", pattern=".*[a-zA-Z].*", minlength=5)
ng-messages(for="myform.name.$error")
ng-message(when="required") Required!
ng-message(when="min") Too small!
input.btn(type='submit')
The resulting HTML: http://plnkr.co/edit/McyMXwW1b2Ae7kkwQ1sP
I'd like to avoid custom directives or much in the way of additional Javascript. What am I doing wrong?
This is happening because you didn't bind ng-model with the input :-)
<input name="name" ng-model="name" required="" pattern=".*[a-zA-Z].*" minlength="5" class="form-control">
<ng-messages for="myform.name.$error">
<ng-message when="minlength">Too small!</ng-message>
<ng-message when="required">Required!</ng-message>
Plunker:- http://plnkr.co/edit/kmNkfhdVOHQsstj6dpPT?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With