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

Validation ([Required]) not working...

3 Answers 535 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Robert Madrian asked on 23 Nov 2016, 05:15 PM

Hi,

I'm using a AutoComplete in my form (Grid Popup Editor template) and all the Validation works except that on the AutoComplete...(see Picture)

here is the Code for the AutoCompleteFor:

<div class="form-group m-xs">
                    <label class="col-sm-2 control-label">Postleitzahl:</label>
                    <div class="col-sm-2">
                        @(Html.Kendo().AutoCompleteFor(m => m.Postleitzahl)
                            .DataTextField("Postleitzahl_ID")
                            .Filter(FilterType.StartsWith).MinLength(1)
                            .NoDataTemplate("Keine Postleitzahl gefunden")
                            .Suggest(true)
                            .Height(300)
                            
                            .DataSource(source =>
                            {
                                source.Read(read =>
                                {
                                    read.Action("Postleitzahl_Read", "Standorte")
                                        .Data("onAdditionalData");
                                })
                                    .ServerFiltering(true);
                            })
                            .Events(e => e
                                .Select("onPostleitzahlSelect")
                            ))
                        @Html.ValidationMessageFor(model => model.Postleitzahl)
                </div>

 

here the part of the model class:

[Required]
[StringLength(8)]
public string Postleitzahl { get; set; }
[Required]
[StringLength(65)]
public string Ort { get; set; }
[Required]
[StringLength(255)]

3 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 24 Nov 2016, 01:25 PM
Hello Robert,

Please find attached the project we used to recreate your scenario implementing a Grid with required AutoCompleteFor inside a Popup editor. I am afraid that we were unable to observe the described issue on our side.

Would you please modify the provided project so that it represents exactly your case and reproduces the issue and send it back to us? Thus, we would be able to investigate locally and help you more efficiently.  

Regards,
Peter Milchev
Telerik by Progress
Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 24 Nov 2016, 02:21 PM

Hi,

I cannot use your Project because of missing Kendo.MVC - what Version you are using?

by the way my project is unter ASP.NET Core and maybe this is the reason why the validation with AutoComplete doesn't work?

robert

 

0
Peter Milchev
Telerik team
answered on 25 Nov 2016, 04:51 PM
Hello Robert,

To run the provided project you should remove the existing reference and add a reference to your Kendo.Mvc.dll assembly. You could find the Kendo version used in the lib/KENDOUIMVC folder - 2016.3.1118.440.Trial.

Since Kendo UI for ASP.NET MVC and Kendo UI for ASP.NET Core are different products, it is important if you use MVC5 or Core.

As for the AutoComplete for ASP.NET Core, there seems to be an issue with the validation using DataAnnotations. We have logged it as a bug and you could follow this Github issue to know when the it is fixed. As a token of gratitude for reporting the issue, we have updated your Telerik points.

Regards,
Peter Milchev
Telerik by Progress
Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
John
Top achievements
Rank 1
commented on 27 Sep 2021, 08:47 PM | edited

I think there is a deeper issue with this control, and that is determining when the AutoComplete has a valid value selected.

Obviously you can hook the Select() event and this will allow you to know when a user has selected an item within the autocomplete control. However, once they have done so there is nothing stopping the user from clearing the control's value or just backspacing over some of the text.  In short, there's no clear way to know that the formerly valid Autocomplete is no longer valid.

You *could* hook the Change() event, but unfortunately when the Select() event is fired, the Change() event comes immediately after. So, every time the user selects something and you get a Select event, your code may think it's valid, but then the Change() event will make your code think it's no longer valid.

Ideally I would suggest this control work more like a dropdown (Html Select control):

1) Maintain both a Display value (Text) and an underlying value (Value) similar to options within a Select

2) When user selects a valid item, populate both values.

3) When the user enters anything into the control to perform an updated search, the underlying value is cleared until they once again select something.  This makes it quite easy to determine whether the user has selected something valid. Just query the control for the underlying value.

Tags
AutoComplete
Asked by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Answers by
Peter Milchev
Telerik team
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Share this question
or