using hiddenfor and textboxfor for the same field is not supported anymore

1 Answer 434 Views
TextBox
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Dan asked on 23 Sep 2022, 03:18 PM

I have an application where in the past I used HiddenFor and TextBoxFor for the same field where the TextBoxFor was disabled.

@Html.HiddenFor(m => m.String)
@Html.Kendo().TextBoxFor(m => m.String).HtmlAttribute(new { @class = "k-state-disabled", disabled = "disabled" })

We are currently trying to upgrade our telerik to the latest version and found this issue.

What is the recommended way of fixing this.

The reason we need this is because the field is on a form and sometimes its disabled and the value needs to be submitted.

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 28 Sep 2022, 10:42 AM

Hi Dan,

By design, HTML elements with the "disabled" attribute are not submitted with the form. With that said, I would recommend disabling the input by setting the CSS attribute "pointer-events: none" which will allow the POST action:

<style>
    .disabled-input {
        opacity: .6;
        pointer-events: none;
    }
</style>

@Html.Kendo().TextBoxFor(m => m.String).HtmlAttributes(new { @class = "disabled-input" })

Alternatively, you can set the "readonly" attribute as is suggested in the SO thread:

https://stackoverflow.com/questions/7357256/disabled-form-inputs-do-not-appear-in-the-request

The difference between "disabled" and "readonly" is that read-only controls can still function and are still focusable, whereas disabled controls can not receive focus and are not submitted with the form and generally do not function as controls until they are enabled.

For example:

<style>
    .disabled-input {
        opacity: .6;
    }
</style>

@Html.Kendo().TextBoxFor(m => m.String).HtmlAttributes(new { @class = "disabled-input", @readonly = "readonly" })

I hope that helps.

Let me know if any of these approaches works for you.

 

Regards, Mihaela Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TextBox
Asked by
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Mihaela
Telerik team
Share this question
or