shole
shole

Reputation: 4094

Kendo MVVM DropDownList does not clear value when selecting option label

I have 2 dropdownlist which initialized using MVVM. One cascade from the other one.

While everything is alright, I found that when I edit the form, and select the dropdownlist to option label (to clear its value, this is valid as it is not a required field), the value is not clear. Therefore after I click save button, the old value is saved.

Both dropdownlist has such behavior. (Select option label did not reset / clear the value of the model bound behind)

How can I bind a null or empty value, or reset the value when I select the option label ?

<select id="ActualNatureCode"
        data-bind="source: DataSource.NatureCategory, value: ViewModel.ActualNature.FailureCategory"
        data-role="dropdownlist"
        data-value-field="Code"
        data-text-field="Description"
        data-option-label="@Resources.Wording.SelectOne"
        data-value-primitive="true"
        data-auto-bind="true"
        ></select>


<select data-bind="source: DataSource.ActualNatureList, value: ViewModel.WorkOrder.ActualNatureCode"
        data-role="dropdownlist"
        data-value-field="Code"
        data-text-field="Description"
        data-option-label="@Resources.Wording.SelectOne"
        data-cascade-from="ActualNatureCode"
        data-value-primitive="true"
        data-auto-bind="false"
        data-select-one="true"
        data-filter="contains"
        ></select>

Upvotes: 0

Views: 760

Answers (1)

Philipp
Philipp

Reputation: 1884

I'm usually not working with KendoUI for ASP.NET, but in Javascript you can set option-label to an object with a custom default value, rather than just a text.

optionLabel: {
    text: "Select one element...",
    id: null
}

You can check the Dojo I created.

I've checked the API reference, and that option is also available for ASP.NET.

Upvotes: 0

Related Questions