@alexsab-ru/scripts 0.8.2 → 0.8.4
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 +9 -4
- package/package.json +1 -1
package/lib/form.js
CHANGED
|
@@ -85,6 +85,7 @@ const propsParams = {
|
|
|
85
85
|
confirmModalText: '',
|
|
86
86
|
verbose: false,
|
|
87
87
|
agreeSelector: "agree",
|
|
88
|
+
sendMailCookie: "SEND_MAIL",
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
export const connectForms = (url, props = propsParams) => {
|
|
@@ -243,7 +244,7 @@ async function submitForm(form){
|
|
|
243
244
|
return;
|
|
244
245
|
} else {
|
|
245
246
|
reachGoal("form_success", formDataObj);
|
|
246
|
-
setCookie(
|
|
247
|
+
setCookie(props.sendMailCookie, true, {'domain': window.location.hostname,'path':'/','expires':600});
|
|
247
248
|
// Вызов callback при успехе
|
|
248
249
|
if (props.callback && typeof props.callback === 'function') {
|
|
249
250
|
props.callback(data);
|
|
@@ -256,7 +257,7 @@ async function submitForm(form){
|
|
|
256
257
|
.catch((error) => {
|
|
257
258
|
reachGoal("form_error");
|
|
258
259
|
console.error("Ошибка отправки данных формы: " + error);
|
|
259
|
-
deleteCookie(
|
|
260
|
+
deleteCookie(props.sendMailCookie);
|
|
260
261
|
// Вызов callback_error при ошибке
|
|
261
262
|
if (props.callback_error && typeof props.callback_error === 'function') {
|
|
262
263
|
props.callback_error(data);
|
|
@@ -269,7 +270,11 @@ async function submitForm(form){
|
|
|
269
270
|
}
|
|
270
271
|
|
|
271
272
|
async function sendForm(form) {
|
|
272
|
-
|
|
273
|
+
let formData = new FormData(form);
|
|
274
|
+
if(formData.get('dealer')) {
|
|
275
|
+
props.sendMailCookie += "_" + formData.get('dealer');
|
|
276
|
+
}
|
|
277
|
+
if (getCookie(props.sendMailCookie)) {
|
|
273
278
|
const confirmModal = document.getElementById('confirm-modal');
|
|
274
279
|
if (confirmModal) {
|
|
275
280
|
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>';
|
|
@@ -285,7 +290,7 @@ async function sendForm(form) {
|
|
|
285
290
|
// Закрываем модальное окно
|
|
286
291
|
confirmModal.classList.add("hidden");
|
|
287
292
|
// Удаляем куку
|
|
288
|
-
deleteCookie(
|
|
293
|
+
deleteCookie(props.sendMailCookie);
|
|
289
294
|
// Повторно отправляем форму
|
|
290
295
|
await submitForm(form);
|
|
291
296
|
return;
|