Open mohdaimash opened 7 years ago
mohdaimash, thank you for the code, I utilized it in my aplication and it helped me (and forced me :) to understand some principles I'd otherwise never worry about :)
If you haven't solved your issue yet, I suppose that the problem happens because the validator calls the "isValidNumber" function before the utils.js script is fully loaded. So using jQuery, my solution was to enclose the initialization of the intTelInput function to $(document).ready AND enclose the custom validator into $(window).load() (since it has to wait for all instances of $(document).ready to complete). And it works fine for me, no more errors on page load: (I did some other minor customisation changes to your code, which shouldn't affect this issue)
telNum = $(".phone");
$(document).ready(function() {
telNum.intlTelInput({
initialCountry: "cz",
utilsScript: "<?php echo htmlspecialchars(SCRIPT_ROOT); ?>assets/js/utils.js",
nationalMode: true,
autoPlaceholder: true,
placeholderNumberType: "MOBILE",
customPlaceholder: '',
preferredCountries: ['cz', 'us', 'gb']
})
});
$(window).on("load",function() {
$("#validated-form").validator({
custom: {
phone: function($el){
return isValidNumber($el);
}
}
}).on('submit', function(e){
$(telNum).val($(telNum).intlTelInput("getNumber"));
});
});
function isValidNumber(num){
telNum = $(num);
if(telNum.intlTelInput('isValidNumber')){
return false;
} else {
return "Vepište prosím validní telefonní číslo dle předepsaného formátu.";
}
}
Hi, First of all, thanks for the amazing and easy to use plugin.
I have been successfully able to integrate the validator plugin with intl-tel-input (https://github.com/jackocnr/intl-tel-input) using the following code:
Where as the code is working perfectly on page, however when its been brought back because of any server side validation error, the phone number field is gives validation error even though the number is correct. A click on the phone number field fixes the issue, is there any way to fix this issue on initialization?
Second I have another question, for data-remote validation I want to perform an function during the time when it is VALIDATING. is there any event in the plugin that can help with that?