Script for setting character limit on multi-line text field

Shawn Horley
Kilo Guru

Greetings folks

I'm needing to set a specific character limit to a multi-line text field of a form variable. I've seen some other articles about this, but most are older and I am concerned that there may be better ways to do this now, and being an utter novice at writing code I have no idea how to actually script it.

The stuff I have tried cobbling together gives me errors galore when I try to build a catalog client script:

find_real_file.png

So as you can see I'm fairly crap when it comes to coding at this time.

Any suggestions will be mightily appreciated.

Cheers

A.

1 ACCEPTED SOLUTION

No, like this...

function onSubmit() {
	var maxLength = 290; // Add desired max length here
	var varName = 'full_description'; // Add variable name here
	var multi = g_form.getValue(varName);
	var len = multi.length;
	if(len > maxLength){
		var str = multi.slice(0, maxLength);
		g_form.setValue(varName, str);
		g_form.showFieldMsg(varName, 'Max length of ' + maxLength.toString() + ' exceeded for this field.', 'error');
                return false;
	}
}

View solution in original post

10 REPLIES 10

AH HA!

That's why I had the var name messed up... much to learn have I.

Thank you for your patience and guidance Mark!

It is much appreciated!