Jim Coyne
Kilo Patron
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
06-04-2013
04:12 PM
Here's a UI Script you can use in the Service Catalog to set the maximum length of a string variable to limit how many characters a user can enter:
Name: u_setMaxLength
Description: Function to set the "maxlength" attribute on an input field
Active: Checked
Global: Checked
Script:
function u_setMaxLength(variableName, size) {
try{
var fieldName = g_form.getControl(variableName).name.toString();
if (Prototype.Browser.IE) {
fieldName.placeholder = size;
} else {
$(fieldName).writeAttribute('maxlength', size);
}
} catch(err) {}
}
You can then call it from an onLoad client script:
function onLoad() {
u_setMaxLength("test123", 5);
}
And now users are limited to just 5 characters for that variable.
It can actually be used in normal forms as well, but probably more useful with Catalog Variables as you cannot define their lengths. Attached is the UI Script XML file for import into your instance.
6 Comments
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.