Enable button when fields are filled in

Asked

Viewed 240 times

0

I know there are already some topics with the same theme, but my case is a little more specific. I have a form with some hidden fields that only appear according to the change of some selects.

I wanted my Submit button to be enabled only when all my fields were filled in, so I found the solution in @Sergio’s reply in this topic:

How to enable a button only when all inputs are completed?

Then the problem begins. The code works, but the button does not activate until all fields occult also be filled in. And often user choices will cause these fields not to appear.

Is there any way to make this code "ignore" these hidden fields? Or just check that they are filled out when they are visible?

Thank you, and follow the code I’m using:

var inputs = $('input').on('keyup', verificarInputs);
function verificarInputs() {
    const preenchidos = inputs.get().every(({value}) => value)
    $('button').prop('disabled', !preenchidos);
}

1 answer

0

You can use a filter to pick up only the inputs that are visible

inputs.filter((i, el) => $(el).is(':visible'))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.