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

How can I share one validation message between two controls?

1 Answer 31 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Glenn
Top achievements
Rank 1
Glenn asked on 22 Jan 2014, 02:32 PM
I'm using MVC.

I have two fields - both IntegerTextBoxes (Html.Kendo().IntegerTextBoxFor....)

These two values are to be validated so that the value in field 1 has to be <= the value in field 2.  I've got a custom validator for this.

So supposing I specify 5 in both fields.
I then change field 1 to equal the value 6 and tab off.  The error is shown against field 1.
I then enter field 2 and tab off.  The error is also shown against field 2 now.  So both fields are showing the error.
If I adjust field 1 to equal 5 again and tab off, the error message disappears against field 1 but it remains against field 2 until I tab in and out of that too.

Is there an easy way to link these into one validation with one validation message?


1 Answer, 1 is accepted

Sort by
0
Glenn
Top achievements
Rank 1
answered on 22 Jan 2014, 02:52 PM
OK found the solution.


<span class="k-invalid-msg" data-for="Baby.NoOfBirths"></span>

and then in the relevant validator rule:

var e = $("span.k-invalid-msg[data-for='Baby.NoOfBirths']");
e.hide();
Tags
Validation
Asked by
Glenn
Top achievements
Rank 1
Answers by
Glenn
Top achievements
Rank 1
Share this question
or