I would like to create a validation message only for dropdownlist.
I'd like to get the text value of label.
label is parent of kendo dropdownlist
var custom = function(input){
if(input.is("[data-role=dropdownlist]")){
if(Utils.isNullOrUndefined(input[0].value) || input[0].value.length === 0){
return true;
}
return input.data("kendoDropDownList").value();
}
return true;
}
rules.custom = custom;
messages.custom = function(input){
"Insert" + input.closest("label").text()
}
var validator = {
validate: function(){
$(".k-invalid:first").focus();
},
rules: rules,
messages: messages
};
return $("#form1").kendoValidator(validator).data("kendoValidator");
This solution doesn't work
5 Answers, 1 is accepted
0
Hello Federico,
In order to set the text from the label as message of the custom rule, you can use the following
I would suggest you to change the structure of the input element and its label, and set them to be siblings
In case the label is parent of the input, by calling the text() method on the label, the text from the input field (text in the DropDownList) will be also retrieved.
I hope you will find the linked Dojo example helpful.
Regards,
Neli
Progress Telerik
In order to set the text from the label as message of the custom rule, you can use the following
messages: {
custom:
function
(input){
return
$(input).parents().find(
'label'
).text();
}
},
I would suggest you to change the structure of the input element and its label, and set them to be siblings
<
label
for
=
"time"
>Start time </
label
>
<
input
id
=
"time"
name
=
"time"
>
In case the label is parent of the input, by calling the text() method on the label, the text from the input field (text in the DropDownList) will be also retrieved.
I hope you will find the linked Dojo example helpful.
Regards,
Neli
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
0

Federico
Top achievements
Rank 1
answered on 23 Jan 2018, 08:49 AM
if I wanted to do it to only those that have the parameter 'required', how should I do?
0
Hello Federico,
You can validate only those with required attribute by checking whether this attribute is present:
The dojo example with this modification added.
Regards,
Ivan Danchev
Progress Telerik
You can validate only those with required attribute by checking whether this attribute is present:
if
(input.is(
"[required][data-role=dropdownlist]"
)) {
The dojo example with this modification added.
Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
0

Federico
Top achievements
Rank 1
answered on 25 Jan 2018, 09:10 AM
This solution doesn't work.
It show:" time is required"
I'd like to show the custom message ("home" for example) for the required dropdownlist.
0
Hi Federico,
Here's the example modified to show custom message and validate only the required DropDownList.
Regards,
Ivan Danchev
Progress Telerik
Here's the example modified to show custom message and validate only the required DropDownList.
Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.