Skip to content Skip to sidebar Skip to footer

Toggle Button Enabled/disabled If At Least One Input Has Values Or If A Select Changes The Default Value

Coming from this related topic where a user leave a solution and it works, I come with a second part where I forgot to mention that the SELECT element has a .select2() applied. If

Solution 1:

Either your could change:

<optionselected="selected"value="-1">-- SELECCIONAR --</option>

To:

<optionselected="selected"value="">-- SELECCIONAR --</option>

OR adjust the js code to:

$(function(){
    $('select.toSelect2').select2();

    $(':input').on('input change', function () {
        var completed = $(':input').filter(function () {
            return !!this.value && !$(this).is('select') || 
                   (this).is('select') && +this.value > -1;
        }).length > 0;
        $('button#btnBuscar').prop('disabled', !completed);
    });        
});

DEMO

Post a Comment for "Toggle Button Enabled/disabled If At Least One Input Has Values Or If A Select Changes The Default Value"