-
Notifications
You must be signed in to change notification settings - Fork 278
/
at_input.js
124 lines (118 loc) · 4.27 KB
/
at_input.js
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
AT.prototype.atInputRendered = [function(){
var fieldId = this.data._id;
var parentData = Template.currentData();
var state = (parentData && parentData.state) || AccountsTemplates.getState();
if (AccountsTemplates.options.focusFirstInput) {
var firstVisibleInput = _.find(AccountsTemplates.getFields(), function(f){
return _.contains(f.visible, state);
});
if (firstVisibleInput && firstVisibleInput._id === fieldId) {
this.$("input#at-field-" + fieldId).focus();
}
}
}];
AT.prototype.atInputHelpers = {
disabled: function() {
return AccountsTemplates.disabled();
},
showLabels: function() {
return AccountsTemplates.options.showLabels;
},
displayName: function() {
var parentData = Template.parentData();
var state = (parentData && parentData.state) || AccountsTemplates.getState();
var displayName = this.getDisplayName(state);
return T9n.get(displayName, markIfMissing=false);
},
optionalText: function(){
return "(" + T9n.get(AccountsTemplates.texts.optionalField, markIfMissing=false) + ")";
},
templateName: function() {
if (this.template)
return this.template;
if (this.type === "checkbox")
return "atCheckboxInput";
if (this.type === "select")
return "atSelectInput";
if (this.type === "radio")
return "atRadioInput";
if (this.type === "hidden")
return "atHiddenInput";
return "atTextInput";
},
values: function(){
var id = this._id;
return _.map(this.select, function(select){
var s = _.clone(select);
s._id = id + "-" + select.value;
s.id = id;
return s;
});
},
errorText: function() {
var err = this.getStatus();
return T9n.get(err, markIfMissing=false);
},
placeholder: function() {
if (AccountsTemplates.options.showPlaceholders) {
var parentData = Template.parentData();
var state = (parentData && parentData.state) || AccountsTemplates.getState();
var placeholder = this.getPlaceholder(state);
return T9n.get(placeholder, markIfMissing=false);
}
},
};
AT.prototype.atInputEvents = {
"focusin input": function(event, t){
var field = Template.currentData();
field.clearStatus();
},
"focusout input, change select": function(event, t){
var field = Template.currentData();
var fieldId = field._id;
var rawValue = field.getValue(t);
var value = field.fixValue(rawValue);
// Possibly updates the input value
if (value !== rawValue) {
field.setValue(t, value);
}
// Client-side only validation
if (!field.validation)
return;
var parentData = Template.parentData();
var state = (parentData && parentData.state) || AccountsTemplates.getState();
// No validation during signIn
if (state === "signIn")
return;
// Special case for password confirmation
if (value && fieldId === "password_again"){
if (value !== $("#at-field-password").val())
return field.setError(AccountsTemplates.texts.errors.pwdMismatch);
}
field.validate(value);
},
"keyup input": function(event, t){
var field = Template.currentData();
// Client-side only continuous validation
if (!field.continuousValidation)
return;
var parentData = Template.parentData();
var state = (parentData && parentData.state) || AccountsTemplates.getState();
// No validation during signIn
if (state === "signIn")
return;
var fieldId = field._id;
var rawValue = field.getValue(t);
var value = field.fixValue(rawValue);
// Possibly updates the input value
if (value !== rawValue) {
field.setValue(t, value);
}
// Special case for password confirmation
if (value && fieldId === "password_again"){
if (value !== $("#at-field-password").val())
return field.setError(AccountsTemplates.texts.errors.pwdMismatch);
}
field.validate(value);
},
};