-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathforms.js
More file actions
127 lines (112 loc) · 2.6 KB
/
forms.js
File metadata and controls
127 lines (112 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import Ember from 'ember';
const {
Controller,
A,
observer,
computed,
isPresent,
later,
computed: { not },
set,
} = Ember;
function asJSON(propKey) {
return computed(`${propKey,propKey}.[]`, function() {
return JSON.stringify(this.get(propKey));
});
}
export default Controller.extend({
frameworks: new A([{
id: 1,
value: 'Materialize CSS'
}, {
id: 2,
value: 'Ember-CLI Materialize'
}]),
message: `This is a long message. It might flow to the next line if I keep typing, so it's better suited to a textarea`,
errors: {
name: A([]),
framework: A([])
},
// BEGIN-SNIPPET form-validation-basic
nameDidChange: observer('model.name', function() {
let messages = [];
if (!isPresent(this.get('model.name'))) {
messages = ['This field is required'];
}
this.get('errors.name').setObjects(messages);
}),
// END-SNIPPET
frameworkDidChange: observer('framework', function() {
let self = this;
later(() => {
let messages = [];
if (!isPresent(self.get('framework'))) {
messages = ['This field is required'];
}
this.get('errors.framework').setObjects(messages);
}, 100);
}),
dateValue: '15 January, 1974',
ageFromDate: computed('dateValue', function() {
let d = new Date(this.get('dateValue'));
return new Date().getFullYear() - d.getFullYear();
}),
rangeValue: 64,
switchValue1: true,
notSwitchValue: not('switchValue'),
switchValue: true,
checkValueOne: false,
checkValueTwo: true,
checkboxIsSelected: false,
radioIsSelected: false,
radioSelection: 2,
otherRadioSelection: 'green',
radioChoices: new A([{
id: 1,
text: 'One'
}, {
id: 2,
text: 'Two'
}]),
radioSelectionString: asJSON('radioSelection'),
radioChoicesString: asJSON('radioChoices'),
checkboxSelections: new A([3, 4]),
checkboxChoices: new A([{
id: 3,
label: 'Three'
}, {
id: 4,
label: 'Four'
}, {
id: 5,
label: 'Five'
}]),
switchesChoicesString: asJSON('switchesChoices'),
switchesChoices: new A([{
key: 6,
name: 'Six'
}, {
key: 7,
name: 'Seven'
}, {
key: 8,
name: 'Eight'
}]),
switchesSelections: new A([7]),
switchesSelection: 7,
switchesSelectionString: asJSON('switchesSelection'),
switchesSelectionsString: asJSON('switchesSelections'),
checkboxChoicesString: asJSON('checkboxChoices'),
checkboxSelectionsString: asJSON('checkboxSelections'),
actions: {
enter() {
console.log('enter');
},
keyPress() {
console.log('key-press');
},
keyUp() {
console.log('key-up');
},
}
});