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

Required

4 Answers 239 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Louis asked on 26 Dec 2012, 05:27 PM
Hello,

I need to use Autcomplete and the field associate with it in my model have a Required attribute.

So in my view despite I have a value in the Autocomplete, I got the message "Required field".  I keep the  @Html.ValidationMessageFor under my @(Html.Telerik().AutoCompleteFor...

How I can keep this validation and avoid "Required field" when I have a value?

Have nice Holidays.

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 28 Dec 2012, 08:50 AM
Hi Louis,

 We couldn't understand what the problem is. Is validation working or not? Could you provide some more code? The model and view would be enough.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 28 Dec 2012, 02:43 PM
This is the code :

In the model :
[Required(ErrorMessageResourceType = typeof(GlobalesResources), ErrorMessageResourceName = "RequiredMessage")]
public string Nom { get; set; }
In the view :
@(Html.Telerik().AutoCompleteFor(model => model.Nom)
           .Name("strNom")
           .ClientEvents(events => events
           .OnError("Grid_onErrorRequestedURLNotReturnJSON")
           )
           .Encode(false)
           .DataBinding(binding => binding.Ajax().Select("ObtenirIdentifications", "LesNoms"))
   )
   @Html.ValidationMessageFor(model => model.Nom)

Even I put a value in the autocomplete, the messsage "Field required" display.





0
Accepted
Atanas Korchev
Telerik team
answered on 28 Dec 2012, 03:03 PM
Hello,

Your autocomplete should be named as the property which it represents in order for validation to work as expected. AutoCompleteFor will do this automatically thus there is no need to set the Name of the widget. Try this:

@(Html.Telerik().AutoCompleteFor(model => model.Nom)
           .ClientEvents(events => events
           .OnError("Grid_onErrorRequestedURLNotReturnJSON")
           )
           .Encode(false)
           .DataBinding(binding => binding.Ajax().Select("ObtenirIdentifications", "LesNoms"))
   )

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 28 Dec 2012, 04:04 PM
It's working #1!!! Thank you Atanas and happy NEW YEAR!!!
Tags
AutoComplete
Asked by
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Atanas Korchev
Telerik team
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or