Pregunta

Is their such a way that a button will automatically be enabled if two or more specific textfields have values e.g. listen for a change in a couple of textfields and enable button once they have values

Any help towards this problem would be greatly appreciated

¿Fue útil?

Solución

I'm assuming that you are using Alloy and in view you have proper objects with ids. textfields it's just simple array with references to all TextFields in view, so it's easier to attach event listener for all of them and check if every single one is empty. You can always reverse this condition and make your button visible only if all of them has value.

var textfields = [$.textfield01, $.textfield02]

function checkTextfield(event) {
    if (this.value !== '') {
        $.button.visible = true;
    } else {
        for (var i in textfields) {
            if (textfields[i].value !== '') {
                return;
            }
        }
        $.button.visible = false;
    }
}

for (var i in textfields) {
    textfields[i].addEventListener('change', checkTextfield);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top