Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var $j = jQuery.noConflict();
- var gfpiElements = [];
- $j(document).bind('gform_post_render', function(event, form_id){
- var gfpValidationJsVars = window["gfpValidationJsVars_"+form_id];
- if (!gfpValidationJsVars) { return; }
- var telInputs = $j(gfpValidationJsVars.elements).toArray();
- gfpiElements = telInputs;
- for (var i = 0; i < telInputs.length; i++) {
- var telInput = $j(telInputs[i]);
- telInput.after('<span class="int-phone valid-msg hide">'+ gfpValidationJsVars.successMessage +'</span>');
- telInput.after('<span class="int-phone error-msg hide">'+ gfpValidationJsVars.failMessage +'</span>');
- telInput.blur(function() {
- wpisValidateIntPhone($j(this));
- });
- telInput.keydown(function() {
- wpisHideValidationErrors($j(this));
- });
- if ( telInput.val().length > 0 ) {
- (function(telInput){
- setTimeout(function(){
- wpisValidateIntPhone(telInput);
- }, 3000);
- })(telInput);
- }
- }// END loop
- });
- function validateAllPhoneFields() {
- if (!Array.isArray(gfpiElements) || gfpiElements.length === 0 || !gfpConfigJsVars.preventWrongPhoneSubmit) { return; }
- const telInputs = gfpiElements;
- let valid = true;
- for (var i = 0; i < telInputs.length; i++) {
- const telInput = $j(telInputs[i]);
- if (!telInput.intlTelInput("isValidNumber")) {
- valid = false;
- }
- }
- if (telInputs[0]) {
- let $submitBtn = $j(telInputs[0]).closest('form').find(':submit');
- if ( valid ) {
- $submitBtn.prop( "disabled", false );
- } else {
- $submitBtn.prop( "disabled", true );
- }
- }
- }
- function wpisHideValidationErrors(telInput) {
- telInput.removeClass("error");
- telInput.parent().parent().find(".error-msg").addClass("hide");
- telInput.parent().parent().find(".valid-msg").addClass("hide");
- }
- function wpisValidateIntPhone(telInput) {
- var errorMsg = telInput.parent().parent().find(".error-msg"),
- validMsg = telInput.parent().parent().find(".valid-msg");
- wpisHideValidationErrors(telInput);
- if ($j.trim(telInput.val())) {
- if (telInput.intlTelInput("isValidNumber")) {
- validMsg.removeClass("hide");
- let nationalPhone = telInput.intlTelInput("getNumber");
- // NEW LINES
- const countryData = telInput.intlTelInput("getSelectedCountryData");
- nationalPhone = nationalPhone.replace(`+${countryData.dialCode}`, `+${countryData.dialCode} `);
- // END NEW LINES
- telInput.val(nationalPhone);
- } else {
- telInput.addClass("error");
- errorMsg.removeClass("hide");
- validMsg.addClass("hide");
- }
- validateAllPhoneFields();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement