Display characters remaining in a field

I’m looking for a way to display the number of characters remaining in a field as the user types. I know how to get the length (number of characters already entered), but I don’t know how to calculate the maximum characters allowed in a given field without hard coding that in.

Also, once I have the calculation, is there a way for the function to run as the user types. I know the onDataChange() method will work, but only when the user is finished and then clicks off the field.

thanks!
Wes

See the keylisteners plugin at Overview - KeyListeners Plugin - ServoyForge

Regards,

Peter

Hello Wes,

If you want to use it in web client, you can try using Jquery keyup function through webClientUtils plugin and return the remaining charecters using callback method.

function getFieldMaxLength(elementName) {
var id = plugins.WebClientUtils.getElementMarkupId(elementName);
	var callBack = plugins.WebClientUtils.generateCallbackScript(callbackMeth,['text_remaining', 'text_max']);
	
	var onKeyUpJs = "$('#"+id+"').keyup(function() {"+
					"var text_length = $('#"+id+"').val().length;"+
					"var text_max = $('#"+id+"').attr('maxlength');"+
				    "var text_remaining = text_max - text_length;"+
					 callBack +
					"});"
						
	plugins.WebClientUtils.executeClientSideJS(onKeyUpJs);
}

function callbackMeth(remaining, max){
	
	elements.lbl_show_remaining.text = remaining +" charecters out of "+ max +" charecters.";
}

Hope this will help you!
If only for smart client you can go for keyListner plugin. I am not sure if it is web client compatible or not.

Thanks

Thank you for the reply. I’m using Smart Client so I’ll give the plugin a try. Sovanm, thank you for the sample solution.