@@ -9,9 +9,7 @@ detection, and preventing invalid form submission.
99<doc:example>
1010<doc:source>
1111 <script>
12- UserForm.$inject = ['$invalidWidgets'];
13- function UserForm($invalidWidgets){
14- this.$invalidWidgets = $invalidWidgets;
12+ function UserForm(){
1513 this.state = /^\w\w$/;
1614 this.zip = /^\d\d\d\d\d$/;
1715 this.master = {
@@ -42,31 +40,34 @@ detection, and preventing invalid form submission.
4240 </script>
4341 <div ng:controller="UserForm">
4442
45- <label>Name:</label><br/>
46- <input type="text" name="form.name" ng:required/> <br/><br/>
43+ <form name="myForm">
4744
48- <label>Address:</label><br/>
49- <input type="text" name="form.address.line1" size="33" ng:required/> <br/>
50- <input type="text" name="form.address.city" size="12" ng:required/>,
51- <input type="text" name="form.address.state" size="2" ng:required ng:validate="regexp:state"/>
52- <input type="text" name="form.address.zip" size="5" ng:required
53- ng:validate="regexp:zip"/><br/><br/>
45+ <label>Name:</label><br/>
46+ <input type="text" ng:model="form.name" required/> <br/><br/>
5447
55- <label>Contacts:</label>
56- [ <a href="" ng:click="form.contacts.$add()">add</a> ]
57- <div ng:repeat="contact in form.contacts">
58- <select name="contact.type">
59- <option>email</option>
60- <option>phone</option>
61- <option>pager</option>
62- <option>IM</option>
63- </select>
64- <input type="text" name="contact.value" ng:required/>
65- [ <a href="" ng:click="form.contacts.$remove(contact)">X</a> ]
66- </div>
67- <button ng:click="cancel()" ng:disabled="{{master.$equals(form)}}">Cancel</button>
68- <button ng:click="save()" ng:disabled="{{$invalidWidgets.visible() ||
69- master.$equals(form)}}">Save</button>
48+ <label>Address:</label> <br/>
49+ <input type="text" ng:model="form.address.line1" size="33" required/> <br/>
50+ <input type="text" ng:model="form.address.city" size="12" required/>,
51+ <input type="text" ng:model="form.address.state" size="2"
52+ ng:pattern="state" required/>
53+ <input type="text" ng:model="form.address.zip" size="5"
54+ ng:pattern="zip" required/><br/><br/>
55+
56+ <label>Contacts:</label>
57+ [ <a href="" ng:click="form.contacts.$add()">add</a> ]
58+ <div ng:repeat="contact in form.contacts">
59+ <select ng:model="contact.type">
60+ <option>email</option>
61+ <option>phone</option>
62+ <option>pager</option>
63+ <option>IM</option>
64+ </select>
65+ <input type="text" ng:model="contact.value" required/>
66+ [ <a href="" ng:click="form.contacts.$remove(contact)">X</a> ]
67+ </div>
68+ <button ng:click="cancel()" ng:disabled="{{master.$equals(form)}}">Cancel</button>
69+ <button ng:click="save()" ng:disabled="{{myForm.$invalid || master.$equals(form)}}">Save</button>
70+ </form>
7071
7172 <hr/>
7273 Debug View:
@@ -90,7 +91,7 @@ master.$equals(form)}}">Save</button>
9091 expect(element(':button:contains(Cancel)').attr('disabled')).toBeFalsy();
9192 element(':button:contains(Cancel)').click();
9293 expect(element(':button:contains(Cancel)').attr('disabled')).toBeTruthy();
93- expect(element(':input[name ="form.name"]').val()).toEqual('John Smith');
94+ expect(element(':input[ng\\:model ="form.name"]').val()).toEqual('John Smith');
9495 });
9596</doc:scenario>
9697</doc:example>
0 commit comments