Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
International Telephone Input JQuery Plugin - Call set instance after ajax html response

I'm using this plugin to validate a tel html input https://github.com/jackocnr/intl-tel-input

I send the form through an ajax response and receive the html structure updated. When I set this html to the page, it loses the plugin instance and it's a normal tel input again, without the plugin instance attached to it. How do I call the previous instance to the new input received that it's technically the same?

// Call and set plugin instance
var inputRec = document.querySelector('#phone_number_rec');
var itiRecruiter = window.intlTelInput(inputRec, {
    hiddenInput: "full",
    initialCountry: "auto",
    geoIpLookup: function(callback) {
        $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
            var countryCode = (resp && resp.country) ? resp.country : "us";
            callback(countryCode);
        });
    },
    utilsScript : base_url + '/public/assets/modules/intl-tel-input-master/build/js/utils.js',
});

// Send form through ajax
// Submit recruiter experience
    $('body').on('submit', '.submit-individual-recruiter', function(e){
        e.preventDefault(e);
        var form = $(this);
        var post_url = $(this).attr('action'); //get form action url
        var form_data = $(this).serialize(); //Encode form elements for submission

        if ($(this)[0].checkValidity() === false) {
            event.stopPropagation();
            form.addClass('was-validated');
        } else {
            $(this).addClass('was-validated');
            var responseState = false;
            var jqxhr = $.ajax({
                url : post_url,
                type: 'post',
                data : form_data,
            }).done(function(response){
                response = JSON.parse(response);
                if(response.result == 'success'){
                    responseState = true;
                    iziToast.success({
                        message: response.message,
                        position: "topRight"
                    });
                } else if(response.result == 'error'){
                    iziToast.error({
                        message: response.message,
                        position: "topRight"
                    });
                }
            });
            
            jqxhr.always(function() {
                if(responseState == true){
                    var $row = $('#recruiter-experience');
        
                    var url = base_url + '/get_info/experience';
                    
                    $.post( url, function( response ) {
                        response = JSON.parse(response);
                        $row.html(response.recruiterView.data);
                    });
                }
            });
        }
    });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

well you replaced the dom, so the element that u initialized the tel-validator is gone.

one thing u could do is wrap your initializer into a function so u can just call it again

function initializeTel() {
    var inputRec = document.querySelector('#phone_number_rec');
    var itiRecruiter = window.intlTelInput(inputRec, {
        hiddenInput: "full",
        initialCountry: "auto",
        geoIpLookup: function(callback) {
            $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
                var countryCode = (resp && resp.country) ? resp.country : "us";
                callback(countryCode);
            });
        },
        utilsScript : base_url + '/public/assets/modules/intl-tel-input-master/build/js/utils.js',
    });
}

// call it initially
initializeTel();



// and then after u received and parsed the response 

initializeTel();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda