This is a migrated thread and some comments may be shown as answers.

Dropdownlist readonly() not recognized

15 Answers 1609 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 16 Apr 2013, 02:28 AM
Hi,

I am evaluating the kendo controls for purchase and I am having trouble setting a kendo dropdown to readonly in mvc 4 using the razor view engine. I keep getting the error

0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'readonly'

My solution is a little more complex but basically I have the below code with a bunch of stuff cut out. Everything works fine until i want to set the dropdown to read only on page load in one of my cases. It seems like I am following the documentation but i can't see to figure out what is wrong.  I've spent a good few hours on this and am out of tricks. I've got access to the dropdown for click events that i set on buttons and such but not during the $(document).ready.

I feel like something in .readonly() is using something not in my jquery but that is only a wild guess.

Thanks in a advance

<script>
//.readonly()doesn't work
  $(document).ready(function () {
        var something = $("#ProvinceRegion").data("kendoDropDownList");
        something.readonly();

//note: something.enable(false); works here just readonly() doesn't

});


//notice I can set .enabled on this function below
    function ClearCustomerClick() {

//all the below work
        var dropdownlist = $("#CustomerName").data("kendoDropDownList")
        dropdownlist.select(0);
        var billContactList = $("#BillingContact").data("kendoDropDownList")
        billContactList.enable(false);
        var billSiteList = $("#BillSite").data("kendoDropDownList")
        billSiteList.enable(false);

    }

</script>

and then my dropdown list is below

@using (Html.BeginForm("ProjectSetupDetails", "Setup", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
                    @(Html.Kendo().DropDownList()
                        .Name("ProvinceRegion")
                        .OptionLabel("Pick a region...")
                        .BindTo(Model.RegionList))

}

15 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 16 Apr 2013, 10:50 AM
Hello Tim,

 
The readonly functionality is available since Q1 2013 (2013.1.319). Before this release the widgets did not have support for readonly. Please verify that you are using the latest official release of Kendo UI.
Check this jsBin demo, which shows how to use readonly method.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tim
Top achievements
Rank 1
answered on 19 Apr 2013, 03:26 AM
Thanks for your reply.

I am currently using the 2012.3.1114.340 for Kendo.MVC dll. I will look into updating the to the latest version to see if I can get readonly to work.

**Update: Georgi's solution worked
0
Development Team
Top achievements
Rank 1
answered on 30 Aug 2016, 05:27 PM

Is there any way to set a kendo dropdown to readonly when using the mvc razor html helpers to generate the control?

All the threads I have found only show examples doing it with the javascript function, but surely there must be a way to do this with razor in c#.

 

0
Eyup
Telerik team
answered on 01 Sep 2016, 06:54 AM
Hi,

You can use the following approach to achieve this requirement:
.HtmlAttributes(new { style = "width:50%", @readonly = "readonly" })

I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
serge
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 17 May 2021, 12:21 PM

using readonly does not allow to switch, setting readonly a false still keeps the control blocked
Eyup
Telerik team
commented on 19 May 2021, 11:12 AM

Can you elaborate on that?
serge
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 01 Jun 2021, 09:11 AM

I mean, if I have a boolean property ReadOnly, I can't use it like "@readonly='@(obj.ReadOnly.ToString())'), readonly should be added, if True, or not to be added (removed) if the property is False...
Eyup
Telerik team
commented on 03 Jun 2021, 08:28 AM

0
Chris
Top achievements
Rank 1
answered on 27 Mar 2019, 10:43 PM
[quote]Eyup said:Hi,

You can use the following approach to achieve this requirement:
.HtmlAttributes(new { style = "width:50%", @readonly = "readonly" })

I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items

[/quote]

 

that only works on the first dropdown in a series of cascaded dropdowns.  Why is that?  The readonly  attribute has absolutely no effect on the 2nd and subsequent dropdowns! 

 

 

0
Chris
Top achievements
Rank 1
answered on 27 Mar 2019, 11:18 PM
So, how exactly do we disable all dropdowns, if they are cascaded together?  Definitely not in the docs anywhere at all.
0
Eyup
Telerik team
answered on 29 Mar 2019, 08:40 AM
Hi Chris,

Kendo provides built-in cascading combo functionality, where the dependent combos are kept in disabled mode until selection is made:
https://demos.telerik.com/kendo-ui/combobox/cascadingcombobox

Alternatively, you can use the $(document).ready() event to access all combos using jQuery and call the readonly method to them:
https://docs.telerik.com/kendo-ui/api/javascript/ui/combobox/methods/readonly

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Chris
Top achievements
Rank 1
answered on 29 Mar 2019, 04:49 PM
Definitely not an acceptable solution.  It readonly doesn't apply in cascaded dropdowns.  There has been many questions about this, but not even one answer from Telerik.
0
Chris
Top achievements
Rank 1
answered on 29 Mar 2019, 06:18 PM
There should be a conditional cascadefrom option, or something along those lines.  Then, if you wanted to conditionally disable all dropdowns, removing cascadefrom would then allow each cascaded dropdown to have a readonly attribute applied.  But, disabling a dropdown in my case, causes the view model values not to be posted back to the server, unless of course I want to write some more code to parse the view model values, which I do not.  so, I want a readonly attribute applied to each cascaded dropdown, which simply does not work because the cascadefrom option is set.
0
Eyup
Telerik team
answered on 02 Apr 2019, 02:54 PM
Hello Chris,

You can use the following approach to disable multiple dropdowns/combos on the page. Could you check the disableDropDowns() method and let me know if this will be suitable for your scenario?
https://dojo.telerik.com/UNinikim/9

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Chris
Top achievements
Rank 1
answered on 02 Apr 2019, 05:23 PM
Hi.  That wasn't a great solution for me.  I got it working by using some razr code with an if statement to create either a cascaded set of dropdowns or non-cascaded dropdowns depending on a flag value.  That was a bit of code duplication, but it worked.  It seems theres really no way to dynamically disable cascaded dropdowns.  I also tried binding to various events to disable/enable the dropdowns, but that extra script tag broke some of my Jquery code that interacted with the dropdowns.
0
Eyup
Telerik team
answered on 03 Apr 2019, 07:34 AM
Hi Chris,

I'm glad that you've managed to find a specific solution for your scenario.

If you want further suggestions on this matter, feel free to send us a modified dojo sample resembling your own configuration so we can provide more precise and accurate solutions.

Alternatively, you can also open a formal support ticket to send us an archive with your project.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
tech
Top achievements
Rank 1
answered on 03 Apr 2020, 04:26 PM

How can I use @readonly attribute conditionally?

Based on some logic it should add readonly 

.HtmlAttributes(new { style = "width:50%", @readonly = "readonly" })

else "not readonly" - 

.HtmlAttributes(new { style = "width:50%" })

How can I achieve it

0
Eyup
Telerik team
answered on 07 Apr 2020, 08:12 AM

Hi,

 

You can try using conditional attributes or custom javascript to achieve this requirement:
- https://www.davidhayden.me/blog/conditional-attributes-in-razor-view-engine-and-asp.net-mvc-4
- https://stackoverflow.com/questions/9399531/asp-net-mvc-razor-conditional-attribute-in-html

I hope this helps.

 

Regards,
Eyup
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
AGGELIKI
Top achievements
Rank 1
Iron
answered on 10 Sep 2021, 08:57 AM
Why can't you just expose to the MVC DDL wrapper a readonly property? Like .Enable ? 
Eyup
Telerik team
commented on 14 Sep 2021, 08:40 AM

Hi Aggeliki,

This seems a nice idea - you can log it in our Public Feedback Portal so it can gather better traction:

https://feedback.telerik.com/aspnet-mvc

Tags
DropDownList
Asked by
Tim
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Tim
Top achievements
Rank 1
Development Team
Top achievements
Rank 1
Eyup
Telerik team
Chris
Top achievements
Rank 1
tech
Top achievements
Rank 1
AGGELIKI
Top achievements
Rank 1
Iron
Share this question
or