telerik / kendo-ui-core

An HTML5, jQuery-based widget library for building modern web apps.
http://www.telerik.com/kendo-ui
Other
2.54k stars 1.91k forks source link

Validation error message shown for a valid DropDownList in a Form #7700

Open IvanDanchev opened 7 months ago

IvanDanchev commented 7 months ago

Bug report

The DropDownList is incorrectly marked as invalid, when another field of the model is invalid.

Reproduction of the problem

Sample project attached. MVCFormValidation.zip

  1. Run the project
  2. Click the submit button. It submits the form and in the submit action a model error is added to a specific field of the model: ModelState.AddModelError("NumberOfShares", "Number not in the expected range");

Current behavior

Two validation errors appear after the form submission: one for the NumberOfShares field and a second one for the Country.Id field, for which a DropDownList editor is used.

Expected/desired behavior

A validation error appears only for the NumberOfShares field. Note that if no editor is specified for the Country.Id field (instead of using a DropDownList editor), e.g.,

    i.Add()
        .Field(f => f.Country.Id)
        .Label(l => l.Text("Country"));

no validation error message is shown for Country.Id.

Environment

gyankov commented 2 months ago

Issue appears because by the time we MVVM bind the form, the drop down data is not yet available on the client. By default the list will skip assigning the value of the input, if the data is not yet bound:

Thus, during validation, the input is still empty, and the required validation fails.

A possible fix would be to assign the input value even though the data is not yet on the client. However, jQuery team should validate that.