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

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

3 Answers 55 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 13 May 2019, 06:10 PM

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;
}

 

3 Answers, 1 is accepted

Sort by
0
Misho
Telerik team
answered on 16 May 2019, 11:05 AM
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.
0
John
Top achievements
Rank 1
answered on 04 Jun 2019, 05:18 PM
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.
0
Misho
Telerik team
answered on 07 Jun 2019, 10:43 AM
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.
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Misho
Telerik team
John
Top achievements
Rank 1
Share this question
or