We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

specify maximum length of text box depending on the value selected from dropdownlist

Thread ID:

Created:

Updated:

Platform:

Replies:

146065 Jul 18,2019 01:27 PM UTC Jul 22,2019 01:25 PM UTC jQuery 1
loading
Tags: ejDropDownList
Ali Ossaily
Asked On July 18, 2019 01:30 PM UTC

Hello Syncfusion Support Team,

I have this Syncfusion dropdownlist and a text box which has value of nameLength (using data-bind knockout value binding)

what i need is when the user select "name1" value from dropdownlist , the max length of nameLength should be equal to 5.
otherwise when the user select "name2" value from dropdownlist , the max length of nameLength should be equal to 10.
when the user select "name3" value from dropdownlist , the max length of nameLength should be equal to 15.

so that , if the user select "name1" , and try to enter a value in text box >5 or <5 number of characters(max length ) , a red error message "cannot insert more than or less than 5 characters" will appear under this textbox .

thanks in advanced.


self.nameLength = ko.observable();


        var items = [
            { name: "name1", id: "1" },
            { name: "name2", id: "2" },
            { name: "name3", id: "3" }
        ];
        $('#nationality').ejDropDownList({
            dataSource: items,
            fields: { text: "name", value: "id" },
            select: function (args) {
                console.log("Value is " + args.value);
            },
            watermarkText: "names",
            width: "100%"
        });



     name:
     


Ashokkumar Balasubramanian [Syncfusion]
Replied On July 22, 2019 01:25 PM UTC

Hi Ali Ossaily, 
 
We analyzed your requirement of set validation rule based on the selection in dropdownlist. We suggested you update the value of each dropdownlist and pass that value to the validationRules in maskedtextbox. 
 
$('#dropdown1').ejDropDownList({ 
 
            dataSource: items, 
 
            fields: { text: "name", value: "id" }, 
 
            validationRules: { required: true }, 
 
            change: function (args) { 
 
                var length; 
 
                if (args.value === "1") length = 5; 
 
                else if (args.value === "2") length = 10; 
 
                else if (args.value === "3") length = 15; 
 
                maskInstance.option('validationRules.value', length); 
 
            } 
 
        }); 
 
Check the condition in validationRules, whether entered character is equal to the value in dropdownlist, if it doesn't show the error message. 
  
$.validator.addMethod("value", 
            function (value, element, params) { 
                if (!/Invalid|NaN/.test(value)) { 
                    return parseInt(value.length) == params; 
                } 
            }, jQuery.validator.format("cannot insert more than or less than {0} characters")); 
 
We have prepared sample for your reference, refer this link 
 
 
Please check the above provided sample and get back to us, if you require any further assistance on this. 
 
Regards, 
Ashokkumar B. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon