Variable attributes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 06:35 PM
For a catalog variable -comments , the user can enter maximum characters up to 1000, how to set this in variable attribute?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 07:41 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 07:53 PM
Not for single line text, it is for multiline text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 09:47 PM
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;
}