-
Notifications
You must be signed in to change notification settings - Fork 3
/
caribou-stepper-step-property-mixin.html
199 lines (178 loc) · 6.56 KB
/
caribou-stepper-step-property-mixin.html
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<script>
window.Caribouflex = window.Caribouflex || {};
Caribouflex.Stepper = Caribouflex.Stepper || {};
/**
* @polymer
* @mixinFunction
*/
Caribouflex.Stepper.StepPropertyMixin = function (superClass) {
return class extends superClass {
static get properties() {
return {
/**
* Property used to indicate if the step is saved.
* True if it's saved, false otherwise.
*/
save: {
type: Boolean,
value: false
},
/**
* Property used to indicate if the step is editable.
* True if it's editable, false otherwise.
*/
editable: {
type: Boolean,
value: false
},
/**
* Property used to indicate if the step is optional.
* True if it's optional, false otherwise.
*/
optional: {
type: Boolean,
value: false
},
/**
* Property used to indicate if the step is active.
* If the step is active that means it will be open, and it's the current step we are focused on.
* True if it's active, false otherwise.
*/
active: {
type: Boolean,
value: false,
reflectToAttribute: true,
observer: 'changeActiveStep'
},
/**
* The continue button text value
* 'Continue' by default
*/
continueLabel: {
type: String,
value: "Continue"
},
/**
* The finish button text value
* 'Finish' by default
*/
finishLabel: {
type: String,
value: "Finish"
},
/**
* The update button text value
* 'Update' by default
*/
updateLabel: {
type: String,
value: "Update"
},
/**
* The skip button text value
* 'Skip' by default
*/
skipLabel: {
type: String,
value: "Skip"
},
/**
* True to display the skip button, false otherwise.
* If the step is linear, the skip button will do nothing, except if the property Optional is true.
*/
skipButton: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* The back button text value
* 'Back' by default
*/
backLabel: {
type: String,
value: "Back"
},
/**
* True to display the back button, false otherwise.
*/
backButton: {
type: Boolean,
value: false
},
/**
* If true this will skip the validation of the input.
* If false all the checkbox will have a native validation check on the input.
*
*/
noInputNativeValidity: {
type: Boolean,
value: false
}
}
}
/**
* This function is used to set the property save to true.
*/
saveStep() {
this.setAttribute("save", true);
}
/**
* Getter used to know if the step is active or not.
* @return {Boolean} True if it is, false otherwise.
*/
isActive() {
return this.active;
}
/**
* This function is used to register an element to the parent.
* @private
*/
_register() {
this.parentElement._registerStep(this);
}
/**
* This function is used to check the validity of the required input.
* This will check the native validation for classic input and call the validate() function for the polymer element.
* @private
*/
_nestedValidate() {
//We check if the validity is required.
if (this.noInputNativeValidity)
return true;
var result = true;
this.querySelectorAll("[required]").forEach(function (el) {
let r;
try {
//Use classic input validation
r = el.checkValidity();
} catch (err) {
//used to try on input that may be polymer input with a validate() function.
try {
r = el.validate();
} catch (err) {
console.log("caribou-step", "Can't validate required input");
}
}
if (!r)
result = false;
});
return result;
}
validate() {
return true;
}
/**
* This function is used to know if the property 'openFirstStepOnStartup' is set to true.
* @private
*/
_getOpenFirstStepOnStartup() {
return this.parentElement.openFirstStepOnStartup;
}
changeActiveStep(active) {
if (active)
this.parentElement.setActiveStep(this);
}
}
}
</script>