-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallBackPhone.js
49 lines (42 loc) · 1.66 KB
/
callBackPhone.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
$(function () {
var CALL_BACK_PHONE_POST_URL = 'https://9j741dyr4k.execute-api.eu-west-2.amazonaws.com/prod/phonesBack';
var MESSAGE_AFTER_SAVE = 'Спасибо за ваши контактные данные';
var REGULAR_SBMT_TEXT = 'ОТПРАВИТЬ';
var SEND_DISABLED_CLASS = 'button_disabled_yes';
var callBackForm = $('#call-back-form');
var phoneInput = callBackForm.find('#phone');
var sendButton = callBackForm.find('button');
phoneInput.mask('+0 (000) 000 00 00', {
onComplete: function (cep) {
sendButton.prop('disabled', false);
sendButton.removeClass(SEND_DISABLED_CLASS);
},
onChange: function (cep){
if (!sendButton.prop('disabled')) {
sendButton.prop('disabled', true);
sendButton.addClass(SEND_DISABLED_CLASS);
}
}
});
callBackForm.on('submit', sendCallBackRequest);
function sendCallBackRequest(event) {
event.preventDefault();
var phone = phoneInput.val();
var loader = new Image();
loader.src = './loader.svg';
sendButton.prop('disabled', true);
sendButton.html(loader);
$.ajax(CALL_BACK_PHONE_POST_URL, {
type: 'POST',
data: JSON.stringify({phone: phone}),
contentType: 'application/json',
crossDomain: true,
complete: function () {
callBackForm[0].reset();
phoneInput.attr('placeholder', MESSAGE_AFTER_SAVE);
sendButton.addClass(SEND_DISABLED_CLASS);
sendButton.html(REGULAR_SBMT_TEXT);
}
});
}
});