|
1 | 1 | define(['dojo/store/Memory', 'dojo/store/Observable', 'dbind/bind', 'dbind/navigation'], function(Memory, Observable, bind, navigation){ |
| 2 | + // create an observable memory store with our test data |
2 | 3 | contactStore = new Observable(new Memory({data:[ |
3 | 4 | {id: 1, firstName: 'Jimi', lastName: 'Hendrix', email: '[email protected]'}, |
4 | 5 | {id: 2, firstName: 'Janis', lastName: 'Joplin', email: '[email protected]'}, |
5 | 6 | {id: 3, firstName: 'Jim', lastName: 'Morrison', email: '[email protected]'}, |
6 | 7 | {id: 4, firstName: 'Kurt', lastName: 'Cobain', email: '[email protected]'}, |
7 | 8 | {id: 5, firstName: 'Amy', lastName: 'Winehouse', email: '[email protected]'}, |
8 | 9 | ]})); |
| 10 | + // create a base binding, that we can set properties on |
9 | 11 | contacts = bind({}); |
10 | 12 | contacts.set('list', contactStore.query({})); |
11 | 13 | contacts.set('select', function(item){ |
12 | 14 | contacts.set('selected', item); |
13 | 15 | }); |
14 | 16 | contacts.set('selected', {firstName: '', lastName: '', id:''}); |
| 17 | + var firstName = contacts.get('selected').get('firstName'); |
| 18 | + firstName.receive(function(value){ |
| 19 | + firstName.set('error', value && value.length < 3 ? 'Name must be at least three characters' : ''); |
| 20 | + }); |
15 | 21 | contacts.set('save', function(selected){ |
16 | 22 | contactStore.put(selected); |
17 | 23 | }); |
18 | 24 | var nextId = 3; |
19 | 25 | contacts.set('create', function(selected){ |
20 | 26 | contacts.set('selected', {firstName:'', lastName: '', email: '', id: nextId++}); |
21 | 27 | }); |
| 28 | + // add navigation support |
22 | 29 | navigation(contacts.get('selected'), { |
23 | 30 | store: contactStore |
24 | 31 | }); |
|
0 commit comments