@@ -9,9 +9,7 @@ detection, and preventing invalid form submission.
9
9
<doc:example>
10
10
<doc:source>
11
11
<script>
12
- UserForm.$inject = ['$invalidWidgets'];
13
- function UserForm($invalidWidgets){
14
- this.$invalidWidgets = $invalidWidgets;
12
+ function UserForm(){
15
13
this.state = /^\w\w$/;
16
14
this.zip = /^\d\d\d\d\d$/;
17
15
this.master = {
@@ -42,31 +40,34 @@ detection, and preventing invalid form submission.
42
40
</script>
43
41
<div ng:controller="UserForm">
44
42
45
- <label>Name:</label><br/>
46
- <input type="text" name="form.name" ng:required/> <br/><br/>
43
+ <form name="myForm">
47
44
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/>
54
47
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>
70
71
71
72
<hr/>
72
73
Debug View:
@@ -90,7 +91,7 @@ master.$equals(form)}}">Save</button>
90
91
expect(element(':button:contains(Cancel)').attr('disabled')).toBeFalsy();
91
92
element(':button:contains(Cancel)').click();
92
93
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');
94
95
});
95
96
</doc:scenario>
96
97
</doc:example>
0 commit comments