• Resolved jonathansavelski

    (@jonathansavelski)


    Hello, I need to show a field depending on another field. Is that possible? Specifically, I need to hide the ‘cuitCuil’ field depending on the user’s country. If the country is not argentina, hide the ‘cuitCuil’ field.

    I tried the following snippet, it hides the field correctly, but it still validating it, so it does not allow the purchase. Could you please help me?

    function ocultarCuitCuilSegunPaisSeleccionado() {
        var paisSeleccionado = jQuery('select#billing_country').val();
        var cuitCuilField = jQuery('#billing_cuitcuil');
        
        if (paisSeleccionado !== 'AR') {
            cuitCuilField.hide();
            cuitCuilField.find('input#billing_cuitcuil').prop('required', false);
        } else {
            cuitCuilField.show();
            cuitCuilField.find('input#billing_cuitcuil').addClass('input-text').attr('name', 'billing_cuitcuil').prop('required', true);
        }
    }
    
    jQuery(document).ready(function($) {
        ocultarCuitCuilSegunPaisSeleccionado();
    
        $('select#billing_country').change(function() {
            ocultarCuitCuilSegunPaisSeleccionado();
        });
    });
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conditional fields’ is closed to new replies.