Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring form input can't be disable

I want to disable a <form:input> with the attribute disabled, but it's not working.

<td class="value">
                <sec:authorize access="hasAnyRole('ROLE_EDIT_DEVICE_INSTALL_DATE')">
                    <form:input path="installDt"  maxlength="10" size="10"  cssClass="installDatePicker" /> 
                    <form:errors path="installDt" cssClass="errormsg" />
                </sec:authorize>
                <sec:authorize access="!hasAnyRole('ROLE_EDIT_DEVICE_INSTALL_DATE')">
                    <form:input path="installDt"  maxlength="10" size="10"  cssClass="installDatePicker" disabled="disabled" /> 
                    <form:errors path="installDt" cssClass="errormsg" />
                </sec:authorize>  
</td>

Does anybody have any idea to solve it ?

like image 352
Jerome Campeaux Avatar asked Apr 01 '15 13:04

Jerome Campeaux


People also ask

How to activate Spring MVC on a form input?

This application needs more than raw HTML. The Spring Initializr created an application class for you. The following listing (from src/main/java/com/example/validatingforminput/ValidatingFormInputApplication.java) shows that class: To activate Spring MVC, you would normally add @EnableWebMvc to the Application class.

What does disabled input mean in HTML?

Definition and Usage. When present, it specifies that the <input> element should be disabled. A disabled input element is unusable and un-clickable. The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.).

How are input fields populated in Spring Boot?

When the page is loaded, the input fields are populated by Spring, which calls the getter of each field bound to an input field. When the form is submitted, the setters are called to save the values of the form to the object.

How do you fix a disabled input element?

A disabled input element is unusable and un-clickable. The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable.


2 Answers

To disable it, use disabled=true. It accepts true|false.

<form:input path="installDt"  maxlength="10" size="10"  cssClass="installDatePicker" disabled="true" />
like image 183
minion Avatar answered Sep 19 '22 13:09

minion


When I try to do input disable with disabled="true" , the data is null at core code, but when I try it with readonly, it did this properly.

Try readonly="readonly"

like image 44
Gorkem Sevim Avatar answered Sep 19 '22 13:09

Gorkem Sevim