Home > Mobile >  Is it possible to disable fileds using th:disabled based on a value from the js file in thymeleaf
Is it possible to disable fileds using th:disabled based on a value from the js file in thymeleaf

Time:09-13

I have few fields which need to be disabled based on a value which is being defined in the js file. Is it possible to do so?

CodePudding user response:

Instead of setting disabled through javascript you could add the disabled to the HTML input element:

<input  id="form_input" disabled="disabled" .... />

Then in your javascript:

document.getElementById('form_input').onchange = function () 
{
    if (this.value == '0') 
    {
        document.getElementById("form_input").disabled = true;
    }

    else 
    {
        document.getElementById("form_input").disabled = false;
    }
}

CodePudding user response:

not sure if it just in JS possible, but with react:


<input   type="xy" disabled={value}/>

then you validate the value with a function in your script.

  • Related