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

always 0 then new object

10 Answers 922 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gusev
Top achievements
Rank 1
Gusev asked on 24 Sep 2013, 09:11 AM
Hello!
I use Combobox  with Ajax Loading.
And I have a question:
1) I have a code:
@model int
            
@(Html.Kendo().ComboBoxFor(x => x)
    .DataTextField("Description")
    .DataValueField("Id")
    .Placeholder("Select")
    .HtmlAttributes(new { style = "width:225px", id = Guid.NewGuid().ToString() })
    .DataSource(databinding => databinding
        .Read(read => read
        .Action("SelectComboboxItems", "Lumber")))
)
2) If I use DropDownListFor instead of ComboBoxFor...everything well works and DropDownList select OptionLabel (because I dont have item with Id = 0)
But If I use ComboboxFor...than I get this...(please see  zero.png)
Why Combobox does this?  I want that combobox set placeholder instead of 0, when I dont have item with Id=0

10 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 26 Sep 2013, 07:38 AM
Hello Gusev,

 
The described behavior is expected, because the ComboBox widget is designed to accept custom values. The default value of int is 0. When you create new item you will see the default value of the integer as ComboBox value. You can either make Model of the editor template Nullable<int> or to clear the value of the widget when Model is 0.

Regards,
Georgi Krustev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 26 Sep 2013, 09:06 AM
Thanks for your answer Georgi Krustev!
How I can do this: "Clear the value of the widget when Model is 0." 
I can subscribe on Event DataBound and then clear value, but how I can do this in EditorTemplate?
0
Georgi Krustev
Telerik team
answered on 30 Sep 2013, 07:10 AM
Hello again Gusev,

 
I will suggest you try clear the default value of the integer using the Value method of the wrapper:

@model int
             
@(Html.Kendo().ComboBoxFor(x => x)
    .Value(Model == 0 ? string.Empty : Model.ToString())
    .DataTextField("Description")
    .DataValueField("Id")
    .Placeholder("Select")
    .HtmlAttributes(new { style = "width:225px", id = Guid.NewGuid().ToString() })
    .DataSource(databinding => databinding
        .Read(read => read
        .Action("SelectComboboxItems", "Lumber")))
)

Regards,
Georgi Krustev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 30 Sep 2013, 09:16 AM
Hello!
I try this method earlier, but ".Value()" in wrapper Combobox doesn't work for me :(
If I use .Value(), then nothing changes.
0
Georgi Krustev
Telerik team
answered on 01 Oct 2013, 01:03 PM
Hello Gusev,

 
If declaratively value setting does not work, then probably widget's value is set subsequently. In that case I will need more information about your current implementation in order to advice you further.

Regards,
Georgi Krustev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 03 Oct 2013, 07:20 AM
my EditorTemplate with name "PlanLumberList"
@model int
              
@(Html.Kendo().ComboBoxFor(x => x)
    .Value(Model == 0 ? string.Empty : Model.ToString())
    .DataTextField("Description")
    .DataValueField("Id")
    .Placeholder("Select")
    .HtmlAttributes(new { style = "width:225px", id = Guid.NewGuid().ToString() })
    .DataSource(databinding => databinding
        .Read(read => read
        .Action("SelectComboboxItems", "Lumber")))
)
my field in class
[Required]
[UIHint("PlanLumberList")]
[Display(Name = "IdLumberDisplay", ResourceType = typeof(LocalizationLumber))]
public virtual int IdLumber { get; set; }
my grid bound column
columns.Bound(o => o.IdLumber).ClientTemplate("#= LumberName #").Width(160);


0
Accepted
Georgi Krustev
Telerik team
answered on 04 Oct 2013, 08:06 AM
Hello Gusev,

 
In that case, you can wire the edit event of the grid. Thus you can get the combobox widget and clear the 
default value:

function edit(e) {
     var combobox = e.container.find("#PlanLumberList").data("kendoComboBox");
     if ( combobox && combobox.value() === "0" ) {
          combobox.value("");
     }
}
Check this link for the other arguments passed to the edit event handler.

Regards,
Georgi Krustev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 04 Oct 2013, 01:45 PM
Hello Georgi Krustev!
Thanks for help. 
1
Osvaldo
Top achievements
Rank 1
answered on 24 Nov 2020, 11:04 PM
 
Sorry but Telerik seems to be missing the basic concept of not creating additional coding efforts and possible bugs to achieve functionality that the standard combo box in any environment implements fluently. I've never been impressed with a single app that used Telerik controls. In almost every situation, it created more work and problems than it hoped to fix.
 
0
Petar
Telerik team
answered on 26 Nov 2020, 11:24 AM

Hi Osvaldo,

Can you be more exact with your feedback about the ComboBox component? What functionality would you like to have when using it? What additional work and issues you have had when using the component? 

This post is already seven years old. I don't know if your comment is related to the current thread but if you haven't worked with our latest product version, I would recommend trying it. Check the Combobox functionalities and let me know what is missing in the current implementation. 

Regards,


Petar
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
ComboBox
Asked by
Gusev
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Gusev
Top achievements
Rank 1
Osvaldo
Top achievements
Rank 1
Petar
Telerik team
Share this question
or