DropDownList readonly property keeps control readonly when readonly=false

1 Answer 1856 Views
DropDownList Grid
serge
Top achievements
Rank 2
Bronze
Iron
Iron
serge asked on 17 May 2021, 12:25 PM | edited on 17 May 2021, 12:30 PM

DropDownList readonly property keeps control readonly when readonly=false

Html.Kendo().DropDownList()
.Name("LayerId")
.HtmlAttributes(new { style = "width:100%;background:#:data.Color#;", @readonly = false })

More than that, if this code is in an EditorTemplate of a Model edited in a grid, there is no way to put readonly property using Model in the view.

Model is always null... @readonly = (Model.SomethingId > 0) throws an error, because Model is null when initialising the Grid

1 Answer, 1 is accepted

Sort by
1
Accepted
Tsvetomir
Telerik team
answered on 20 May 2021, 07:31 AM

Hi, Serge,

The default behavior of the readonly attribute is to make the respective input read-only whenever it is present. Regardless if you are setting it to true or false, if it present, it will apply its functionality. In order to make an input editable again, you should remove the attribute with JavaScript. 

Find more information in the following article:

https://www.w3schools.com/tags/att_input_readonly.asp

As per the EditorTemplate, the Model would be null due to the fact that the template creates the skeleton/placeholders for the editable row. Upon editing, the binding happens on the client-side via the placeholders and the data item's properties. 

If you would like to have a widget conditionally read-only, I recommend applying JavaScript logic inside the Edit event.

 

Best regards,
Tsvetomir
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
DropDownList Grid
Asked by
serge
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Tsvetomir
Telerik team
Share this question
or