ValidationMessage for dropdownlist

6 posts, 0 answers
  1. Federico
    Federico avatar
    6 posts
    Member since:
    Jan 2018

    Posted 19 Jan 2018 Link to this post

    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

     

     

     

  2. Neli
    Admin
    Neli avatar
    357 posts

    Posted 22 Jan 2018 Link to this post

    Hello Federico,

    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.
  3. Federico
    Federico avatar
    6 posts
    Member since:
    Jan 2018

    Posted 23 Jan 2018 in reply to Neli Link to this post

    if I wanted to do it to only those that have the parameter 'required', how should I do?
  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2129 posts

    Posted 25 Jan 2018 Link to this post

    Hello Federico,

    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.
  5. Federico
    Federico avatar
    6 posts
    Member since:
    Jan 2018

    Posted 25 Jan 2018 Link to this post

    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.

     

  6. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2129 posts

    Posted 26 Jan 2018 Link to this post

    Hi Federico,

    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.
Back to Top