Variable attributes

User267
Tera Contributor

For a catalog variable -comments , the user can enter maximum characters up to 1000, how to set this in variable attribute?

3 REPLIES 3

Jerick I
Kilo Sage
Kilo Sage

@User267 try to use max_length Sets the maximum number of characters allowed in the field. By default, the field accepts long strings of text, several thousand characters. Set the max_length attribute as appropriate for the information the variable is collecting. For example, to allow for entry of an address, set max_length=200, or other appropriate length.

Applicable variables: Single-line text, Wide single-line text

 

If the above max length will not suffice your requirement try to use a client script.

 

Please write a On Change Catalog Client Script on your variable and use the script below:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue) {
        var myFieldValue = g_form.getValue('Variable Name');
        if (myFieldValue.toString().length < 3) { // or whatever number you want
            g_form.setValue('your_field', '');
            alert('Please enter 3 or more characters.');
        }else if(myFieldValue.toString().length > 100){
			g_form.setValue('your_field', '');
            alert('Please enter less than 100 characters.');
		}
    }
}

Regards,

Jeff

Hope this helps. Please mark the answer as correct/helpful based on impact.

User267
Tera Contributor

Not for single line text, it is for multiline text.

Harish Bainsla
Tera Sage
Tera Sage

function onSubmit() {
var maxCharacters = 1000;
var commentsValue = g_form.getValue('variable_name');

if (commentsValue && commentsValue.length > maxCharacters) {
g_form.addErrorMessage("Maximum character limit is " + maxCharacters);
return false;
}

return true;
}