$(document).ready(function () { $(function () { // set dropdown if ($('#bookletdownload-country-dropdown').length > 0) { var contactusCountryDropdown = new Menubutton(document.getElementById('bookletdownload-country-dropdown')); contactusCountryDropdown.init(); } // add focus to bookletdownload__submit $('.bookletdownload__submit').attr('tabindex', 0); $('.bookletdownload__submit').on('click', function (e) { bookletDownloadFormSubmit(e); }); $(document).on('keydown', "#bookletdownloadForm input", function (e) { if (e.keyCode == 13) { bookletDownloadFormSubmit(e); } }); }); function bookletDownloadFormSubmit(e) { var isError = false; e.preventDefault(); $('.checkbox-with-desc').each(function () { var input = $(this).find('input'); if (input.attr('required') && !input.is(':checked')) { isError = true; $(this).find('.error-msg').show(0); } else { $(this).find('.error-msg').hide(0); } }); var result = checkValidation({ targetForm: "bookletDownloadForm" }); if (result && !isError) { $('.contactus__message').remove(); var requestPage_1 = apiDomain + '/api/booklet_download_form?language=' + htmlLang; var formData = $('#bookletDownloadForm').serialize(); sendContactusRequest(requestPage_1, formData); $('.bookletdownload__submit').addClass('hidden'); $('
').appendTo($('.bookletdownload__submit').parents('.m-form__section')); } } function sendContactusRequest(requestPage, formData) { // get session token $.ajax({ url: apiDomain + "?q=services/session/session_token", type: "get", crossDomain: true, xhrFields: { withCredentials: true }, dataType: "text", error: function (jqXHR, textStatus, errorThrown) { //alert(errorThrown); }, success: function (token) { var sessionToken = token; $.ajax({ method: "POST", url: requestPage, //dataType : 'jsonp', data: formData, crossDomain: true, xhrFields: { withCredentials: true }, headers: { 'X-CSRF-Token': sessionToken } }).done(function (data) { if (data.is_sent == 'success') { window.location.href = data.link + '?from=bookletDownloadForm'; // download pdf file var $bookletDownloadForm = $('#bookletDownloadForm'); if ($bookletDownloadForm.data('form-type') === "booklet_download") { var link = $bookletDownloadForm.data('booklet-pdf-link'); if (link) { var a = document.createElement('a'); a.href = link; a.download = link.split('/').pop(); document.body.appendChild(a); a.click(); document.body.removeChild(a); } } } else if (data.is_sent == 'fail') { $('.bookletdownload__submit').removeClass('hidden'); $('.loader').remove(); var errorMsg_1 = ''; $.each(data.message, function (index, item) { if (index == 0) { errorMsg_1 += item; } else { errorMsg_1 = errorMsg_1 + '
' + item; } }); $('
' + errorMsg_1 + '
').insertAfter($('#bookletDownloadForm')); $('.contactus__message').fadeIn(); } }); } }); } // not allow number for input $(document).on('keydown', '#m-lastName, #m-firstName', function (e) { if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)) { return false; } }); });