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

Combobox fails to post updated values after initial modelstate fail

2 Answers 161 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 30 Aug 2017, 10:08 PM

All our Combo Boxes are defined similar to this:

@(Html.Kendo().ComboBoxFor(model => model.PortOfLoadingId)
    .Filter(FilterType.Contains)
    .Suggest(true)
    .Placeholder("Select port...")
    .DataTextField("Text")
    .DataValueField("Id")
    .DataSource(s =>
    {
        s.Ajax().Read(r =>
        {
            r.Action("GetComboBoxItems", "Ports");
        });
    })
    .Events(e => e.Select("portSelected"))
)
    

2 Answers, 1 is accepted

Sort by
0
Allan
Top achievements
Rank 1
answered on 30 Aug 2017, 10:13 PM

Sorry, i can't edit top post which submitted by accident.

When the user types an invalid value in the combo box field that does not match any of the items, and submits the form, the correct modelstate is generated saying the value is invalid.  The user is then directed back to the View:

            if (!ModelState.IsValid)
            {
                BeforeCreate(ref viewModel);
                return View(viewModel);
            }
But no matter what the User does the ModelState will always be invalid for that combo box field.  Is this a bug since I thought changing the value again should clear the ModelState for that property?

0
Ianko
Telerik team
answered on 01 Sep 2017, 11:47 AM

Hello Allan,

 

Typically, changing the value of the ComboBox (from the UI) to a valid one should make the ViewModel valid. And process the form submission as usual.

 

Can you please provide some more details about the validation and whether this is a simple form or an AJAX form? It would be best if you can provide a small example that can be locally run and examined.  

 

Regards,
Ianko
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Allan
Top achievements
Rank 1
Answers by
Allan
Top achievements
Rank 1
Ianko
Telerik team
Share this question
or