How can I tell what input validator.validate() is failing on?

4 posts, 0 answers
  1. John
    John avatar
    37 posts
    Member since:
    Apr 2015

    Posted 13 May 2019 Link to this post

    I have a form Razor in .NET Core that I have attached a Kendo Validator to.  When I submit the form validator.validate() is returning false but none of the inputs on the form are displaying a validation error.  How can I tell what validations are failing when validator.validate() returns false?

    Razor Form 

    <form id="editQuestionsForm" method="post">
        <input asp-for="Input.InspectionQuestionId" type="hidden" />
     
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label asp-for="Input.InspectionSectionId"></label><br />
                    <kendo-combobox name="inspectionSection" style="width: 500px;"
                                    for="Input.InspectionSectionId"
                                    placeholder="Select Section"
                                    datatextfield="Text"
                                    datavaluefield="Value"
                                    bind-to="Model.InspectionSections">
                        <popup-animation>
                            <open duration="500" />
                            <close duration="500" />
                        </popup-animation>
                    </kendo-combobox><br />
                    <span asp-validation-for="Input.InspectionSectionId" class="text-danger"></span>
                </div>
            </div>
        </div>
     
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label asp-for="Input.QuestionTextForForm"></label><br />
                    <textarea asp-for="Input.QuestionTextForForm" class="form-control-textarea"></textarea><br />
                    <span asp-validation-for="Input.QuestionTextForForm" class="text-danger"></span>
                </div>
            </div>
        </div>
     
    </form>

     

    JavaScript

    var validator = $("#editQuestionsForm").kendoValidator().data("kendoValidator");
     
    function validateSave() {
        if (validator.validate()) {
            $('#editQuestionsForm').submit();
        } else {
            bootstrapWarningsMessage("There was an error submitting the form.");
        }
        return true;
    }

     

  2. Misho
    Admin
    Misho avatar
    229 posts

    Posted 16 May 2019 Link to this post

    Hello,

    You could attach to the validate event of Kendo validator and get the validator instance which fired the event through the e.sender in the event handler:
    https://docs.telerik.com/kendo-ui/api/javascript/ui/validator/events/validate

    I hope this helps.

    Best Regards,
    Misho
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. John
    John avatar
    37 posts
    Member since:
    Apr 2015

    Posted 04 Jun 2019 in reply to Misho Link to this post

    That worked and e.sender is "init".  But it still isn't helping me figure out exactly what control on the form is failing validation.
  4. Misho
    Admin
    Misho avatar
    229 posts

    Posted 07 Jun 2019 Link to this post

    Hello John,

    Here is a sample with two inputs that shows how you could check whether an exact control on the page is failing validation based on validateInput method: https://dojo.telerik.com/ODAzUjIT/3

    You could also review the following resources for Kendo validator which might be helpful:
    https://docs.telerik.com/kendo-ui/api/javascript/ui/validator/events/validateinput
    https://docs.telerik.com/kendo-ui/controls/editors/validator/overview
    https://docs.telerik.com/kendo-ui/controls/editors/validator/how-to/add-red-border

    I hope you will find this information helpful.

    Best Regards,
    Misho
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top