tonder-web-sdk 1.9.2-beta.1 → 1.9.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/helpers/skyflow.js +46 -6
package/package.json
CHANGED
package/src/helpers/skyflow.js
CHANGED
|
@@ -74,7 +74,8 @@ export async function initSkyflow(
|
|
|
74
74
|
|
|
75
75
|
handleSkyflowElementEvents(
|
|
76
76
|
cardHolderNameElement,
|
|
77
|
-
"titular de la tarjeta"
|
|
77
|
+
"titular de la tarjeta",
|
|
78
|
+
collectStylesOptions.errorTextStyles
|
|
78
79
|
);
|
|
79
80
|
|
|
80
81
|
// Create collect elements.
|
|
@@ -94,7 +95,8 @@ export async function initSkyflow(
|
|
|
94
95
|
|
|
95
96
|
handleSkyflowElementEvents(
|
|
96
97
|
cardNumberElement,
|
|
97
|
-
"número de tarjeta"
|
|
98
|
+
"número de tarjeta",
|
|
99
|
+
collectStylesOptions.errorTextStyles
|
|
98
100
|
);
|
|
99
101
|
|
|
100
102
|
const cvvElement = await collectContainer.create({
|
|
@@ -107,6 +109,12 @@ export async function initSkyflow(
|
|
|
107
109
|
validations: [regexMatchRule],
|
|
108
110
|
});
|
|
109
111
|
|
|
112
|
+
handleSkyflowElementEvents(
|
|
113
|
+
cvvElement,
|
|
114
|
+
"",
|
|
115
|
+
collectStylesOptions.errorTextStyles
|
|
116
|
+
);
|
|
117
|
+
|
|
110
118
|
const expiryMonthElement = await collectContainer.create({
|
|
111
119
|
table: "cards",
|
|
112
120
|
column: "expiration_month",
|
|
@@ -117,6 +125,12 @@ export async function initSkyflow(
|
|
|
117
125
|
validations: [regexMatchRule],
|
|
118
126
|
});
|
|
119
127
|
|
|
128
|
+
handleSkyflowElementEvents(
|
|
129
|
+
expiryMonthElement,
|
|
130
|
+
"",
|
|
131
|
+
collectStylesOptions.errorTextStyles
|
|
132
|
+
);
|
|
133
|
+
|
|
120
134
|
const expiryYearElement = await collectContainer.create({
|
|
121
135
|
table: "cards",
|
|
122
136
|
column: "expiration_year",
|
|
@@ -127,6 +141,12 @@ export async function initSkyflow(
|
|
|
127
141
|
validations: [regexMatchRule],
|
|
128
142
|
});
|
|
129
143
|
|
|
144
|
+
handleSkyflowElementEvents(
|
|
145
|
+
expiryYearElement,
|
|
146
|
+
"",
|
|
147
|
+
collectStylesOptions.errorTextStyles
|
|
148
|
+
);
|
|
149
|
+
|
|
130
150
|
await mountElements(
|
|
131
151
|
cardNumberElement,
|
|
132
152
|
cvvElement,
|
|
@@ -162,23 +182,43 @@ async function mountElements(
|
|
|
162
182
|
}
|
|
163
183
|
|
|
164
184
|
|
|
165
|
-
function handleSkyflowElementEvents(element, fieldMessage= "", requiredMessage = "El campo es requerido", invalidMessage= "El campo es inválido") {
|
|
185
|
+
function handleSkyflowElementEvents(element, fieldMessage= "", error_styles = {}, resetOnFocus = true, requiredMessage = "El campo es requerido", invalidMessage= "El campo es inválido") {
|
|
166
186
|
if ("on" in element) {
|
|
167
187
|
element.on(Skyflow.EventName.CHANGE, (state) => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
188
|
+
// console.log("state chan:", state)
|
|
189
|
+
updateErrorLabel(element, error_styles, "transparent")
|
|
190
|
+
// if(state.isValid && !state.isEmpty){
|
|
191
|
+
// element.resetError();
|
|
192
|
+
// }
|
|
171
193
|
});
|
|
172
194
|
|
|
173
195
|
element.on(Skyflow.EventName.BLUR, (state) => {
|
|
196
|
+
console.log("state blur:", state)
|
|
174
197
|
if (!state.isValid) {
|
|
175
198
|
const msj_error = state.isEmpty ? requiredMessage : fieldMessage != "" ?`El campo ${fieldMessage} es inválido`: invalidMessage;
|
|
199
|
+
// updateErrorLabel(element, error_styles)
|
|
176
200
|
element.setError(msj_error);
|
|
177
201
|
}
|
|
202
|
+
updateErrorLabel(element, error_styles)
|
|
178
203
|
});
|
|
179
204
|
|
|
180
205
|
element.on(Skyflow.EventName.FOCUS, (state) => {
|
|
206
|
+
updateErrorLabel(element, error_styles, "transparent")
|
|
181
207
|
element.resetError();
|
|
182
208
|
});
|
|
183
209
|
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function updateErrorLabel(element, errorStyles, color = "red" ){
|
|
213
|
+
if(Object.keys(errorStyles).length > 0){
|
|
214
|
+
element.update({
|
|
215
|
+
errorTextStyles: {
|
|
216
|
+
...errorStyles,
|
|
217
|
+
base: {
|
|
218
|
+
...errorStyles.base,
|
|
219
|
+
color
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
}
|
|
184
224
|
}
|