@alexsab-ru/scripts 0.8.4 → 0.9.0
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/lib/form.js +19 -12
- package/package.json +1 -1
package/lib/form.js
CHANGED
|
@@ -78,10 +78,10 @@ const showMessageModal = (messageModal, icon, message) => {
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
const propsParams = {
|
|
81
|
-
callback: null,
|
|
82
|
-
callback_error: null,
|
|
81
|
+
callback: null,
|
|
82
|
+
callback_error: null,
|
|
83
83
|
validation: null,
|
|
84
|
-
ct_routeKey: '',
|
|
84
|
+
ct_routeKey: '',
|
|
85
85
|
confirmModalText: '',
|
|
86
86
|
verbose: false,
|
|
87
87
|
agreeSelector: "agree",
|
|
@@ -96,7 +96,7 @@ export const connectForms = (url, props = propsParams) => {
|
|
|
96
96
|
element.addEventListener("input", maskphone);
|
|
97
97
|
element.addEventListener("change", () => phoneChecker(element));
|
|
98
98
|
});
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
// AGREE CHECKBOX
|
|
101
101
|
// Проверка на состояние чекбокса, показ/скрытие ошибки
|
|
102
102
|
document.querySelectorAll("input[name=" + props.agreeSelector + "]").forEach(function (element) {
|
|
@@ -109,7 +109,7 @@ export const connectForms = (url, props = propsParams) => {
|
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
// CHANGE textarea для всез браузеров
|
|
114
114
|
document.querySelectorAll("textarea").forEach(function (textarea) {
|
|
115
115
|
if (textarea.addEventListener) {
|
|
@@ -128,7 +128,7 @@ export const connectForms = (url, props = propsParams) => {
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
async function submitForm(form){
|
|
133
133
|
const btn = form.querySelector('[type="submit"]');
|
|
134
134
|
const btnText = btn.value || btn.innerText;
|
|
@@ -163,6 +163,10 @@ async function submitForm(form){
|
|
|
163
163
|
reachGoal("form_submit");
|
|
164
164
|
|
|
165
165
|
let formData = new FormData(form);
|
|
166
|
+
let sendMailCookie = props.sendMailCookie;
|
|
167
|
+
if(formData.get('dealer')) {
|
|
168
|
+
sendMailCookie += "_" + formData.get('dealer');
|
|
169
|
+
}
|
|
166
170
|
if(getCookie('fta')) {
|
|
167
171
|
formData.append("fta", true);
|
|
168
172
|
}
|
|
@@ -243,8 +247,10 @@ async function submitForm(form){
|
|
|
243
247
|
}
|
|
244
248
|
return;
|
|
245
249
|
} else {
|
|
246
|
-
|
|
247
|
-
|
|
250
|
+
if(data.attention != true) {
|
|
251
|
+
reachGoal("form_success", formDataObj);
|
|
252
|
+
}
|
|
253
|
+
setCookie(sendMailCookie, true, {'domain': window.location.hostname,'path':'/','expires':600});
|
|
248
254
|
// Вызов callback при успехе
|
|
249
255
|
if (props.callback && typeof props.callback === 'function') {
|
|
250
256
|
props.callback(data);
|
|
@@ -257,7 +263,7 @@ async function submitForm(form){
|
|
|
257
263
|
.catch((error) => {
|
|
258
264
|
reachGoal("form_error");
|
|
259
265
|
console.error("Ошибка отправки данных формы: " + error);
|
|
260
|
-
deleteCookie(
|
|
266
|
+
deleteCookie(sendMailCookie);
|
|
261
267
|
// Вызов callback_error при ошибке
|
|
262
268
|
if (props.callback_error && typeof props.callback_error === 'function') {
|
|
263
269
|
props.callback_error(data);
|
|
@@ -271,10 +277,11 @@ async function submitForm(form){
|
|
|
271
277
|
|
|
272
278
|
async function sendForm(form) {
|
|
273
279
|
let formData = new FormData(form);
|
|
280
|
+
let sendMailCookie = props.sendMailCookie;
|
|
274
281
|
if(formData.get('dealer')) {
|
|
275
|
-
|
|
282
|
+
sendMailCookie += "_" + formData.get('dealer');
|
|
276
283
|
}
|
|
277
|
-
if (getCookie(
|
|
284
|
+
if (getCookie(sendMailCookie)) {
|
|
278
285
|
const confirmModal = document.getElementById('confirm-modal');
|
|
279
286
|
if (confirmModal) {
|
|
280
287
|
confirmModal.querySelector('p').innerHTML = props.confirmModalText || '<span style="color: tomato; font-weight: bold">ПЕРЕДАЙ ТЕКСТ В ОБЪЕКТЕ <br><pre style="color: black; font-weight: 400">props = {confirmModalText: <i>"text"</i>}</pre></span>';
|
|
@@ -290,7 +297,7 @@ async function sendForm(form) {
|
|
|
290
297
|
// Закрываем модальное окно
|
|
291
298
|
confirmModal.classList.add("hidden");
|
|
292
299
|
// Удаляем куку
|
|
293
|
-
deleteCookie(
|
|
300
|
+
deleteCookie(sendMailCookie);
|
|
294
301
|
// Повторно отправляем форму
|
|
295
302
|
await submitForm(form);
|
|
296
303
|
return;
|