Wrong validation message shown for Combobox when using kendoValidator

0 Answers 191 Views
ComboBox Validation
Faz
Top achievements
Rank 1
Iron
Faz asked on 23 Aug 2021, 06:02 AM | edited on 23 Aug 2021, 06:23 AM

I'm trying to get the validation working on my form with kendovalidator

I'm using Telerik ver : 2019.2.619

    $.validator.setDefaults({
        ignore: ""
    });
    $(function () {
        $("#form1").kendoValidator();
    });

this shows validation messages correctly if values are empty eg:

issue is  when an incorrect value is entered the message shows:

 


    <div class="form-group row">
        @Html.LabelFor(model => model.CountryCodeId, htmlAttributes: new { @class = "control-label col-md-2 required" })
        <div class="col-md-10">
            @(Html.Kendo().ComboBoxFor(m => m.CountryCodeId)
                                         .Name("CountryCodeId")
                                        .Placeholder(@Resources.Resources.CountryPlaceholder)
                                        .DataTextField("Description")
                                        .DataValueField("Id")
                                        .Filter("contains")
                                        .Suggest(true)
                                        .DataSource(s => s.Read(r => r.Action("GetCountries", "Customer")).ServerFiltering(false))
                                        .HtmlAttributes(new {  style = "width:300px" })
            )
            @Html.ValidationMessageFor(model => model.CountryCodeId, "", new { @class = "text-danger" })
        </div>
    </div>



        [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "CountryValidation")]
        [Display(ResourceType = typeof(Resources.Resources), Name = "Country")]
        public int? CountryCodeId { get; set; }

and if  I enter a number the validation seems to pass, which it shouldn't

Validation should pass only if a country is selected from the combobox, entrering a numeric value or any other text which is not on the list should fail validation

How do I get default dataanotation message if an invalid entry is made?

Thanks

 

Martin
Telerik team
commented on 25 Aug 2021, 01:05 PM

Thank you for sharing the configuration for the ComboBox. However, I cannot see the custom messages you have configured for it through the Kendo Validator like the ones in the Custom Validation demo. Could you please share how are you defining the custom messages through the Validator? Sharing a small runnable project will be really helpful as I can debug it directly.
Faz
Top achievements
Rank 1
Iron
commented on 26 Aug 2021, 09:18 AM

Hi Martin

Custom message comes from an xml file, just a key value pair. it wasn't the issue. I removed it replaced it with a string. please see attached doc for details.

Thanks

Martin
Telerik team
commented on 31 Aug 2021, 08:37 AM

The validation passes when you enter an integer because the value entered is most probably associated with a dataItem that has the same value. For example, if you have a dataitem with text "description 4" and id 4, when you enter 4 in the input field, the widget finds the dataItem that has id 4 and displays the corresponding text. I hope that clears the matter. Let me know if I am missing something.

No answers yet. Maybe you can help?

Tags
ComboBox Validation
Asked by
Faz
Top achievements
Rank 1
Iron
Share this question
or