Prevent multiple values in a List type field

George56
Tera Contributor

Hello,

 

We have a Vendor Manager List type field on the Company table which references the user table.  Is there a way to prevent users from entering more than 1 name in the Vendor Manager field being that it is a list type?

 

Thanks

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

Hi @George56 ,

 

You can achieve this by creating an onChange client script on vendor management field

 

(function() {

    // When Vendor Manager field changes

    function onChangeVendorManager() {

        var vendorManagerField = g_form.getValue('vendor_manager'); // Replace 'vendor_manager' with the actual field name

        var enteredNames = vendorManagerField.value.split(','); // Assuming names are separated by commas

 

        if (enteredNames.length > 1) {

            alert('Please enter only one name in the Vendor Manager field.');

            vendorManagerField.value = enteredNames[0]; // Set the field value to the first name entered

        }

    }

})();

 

Please modify the script as per your need.But the basic idea is on change of the field fetch the value check the length by splitting it with comma n validating of it's more than 1 or not. If more than 1 give some alert or fieldmessage.

 

Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

View solution in original post

2 REPLIES 2

Danish Bhairag2
Tera Sage
Tera Sage

Hi @George56 ,

 

You can achieve this by creating an onChange client script on vendor management field

 

(function() {

    // When Vendor Manager field changes

    function onChangeVendorManager() {

        var vendorManagerField = g_form.getValue('vendor_manager'); // Replace 'vendor_manager' with the actual field name

        var enteredNames = vendorManagerField.value.split(','); // Assuming names are separated by commas

 

        if (enteredNames.length > 1) {

            alert('Please enter only one name in the Vendor Manager field.');

            vendorManagerField.value = enteredNames[0]; // Set the field value to the first name entered

        }

    }

})();

 

Please modify the script as per your need.But the basic idea is on change of the field fetch the value check the length by splitting it with comma n validating of it's more than 1 or not. If more than 1 give some alert or fieldmessage.

 

Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

Thanks Danish.  I had to make a couple minor changes, but this got me down the right path, Thanks again.