Required

5 posts, 1 answers
  1. Louis
    Louis avatar
    42 posts
    Member since:
    Jun 2011

    Posted 26 Dec 2012 Link to this post

    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.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Dec 2012 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Louis
    Louis avatar
    42 posts
    Member since:
    Jun 2011

    Posted 28 Dec 2012 Link to this post

    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.





  5. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Dec 2012 Link to this post

    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!
  6. Louis
    Louis avatar
    42 posts
    Member since:
    Jun 2011

    Posted 28 Dec 2012 Link to this post

    It's working #1!!! Thank you Atanas and happy NEW YEAR!!!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready