Get the max field length for a text area using Javascript

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

Get the max field length for a text area using Javascript

#1

Postby Jez » Fri Sep 16, 2016 10:02 am

Hello,

I am a Javascript newbie, so I am hoping someone can help me with this...

Is it possible to get the maximum field Length for a textarea form field using Javascript?

We used to do this in Ebase 3.4 using the following code...

Code: Select all

var maxTextLength;
	if( sourceObj.type == 'textarea' )
	{
 		for ( var i in fieldArray )
		{
			if( sourceObj.name == fieldArray[i].fieldName )
			{
				maxTextLength = fieldArray[i].maxLength;
				break;
			}
		}
	}
Here sourceObj is a textarea control. This code does not work any more in Ebase v4.5, and gives a "'fieldArray' is undefined" error

It seems that the way maximum field lengths are stored has changed since Ebase v3.4. What is the recommended way of getting the maximum field Length for a textarea in Ebase v4.5?

Thanks in advance for your help.
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Mon Sep 19, 2016 10:13 am

Something like this..

Code: Select all

function findMaxLength(sourceObj)
{
    if(!com.ebasetech.ufs.Util.isUndefinedOrNull(sourceObj) && !com.ebasetech.ufs.Util.isUndefinedOrNull(sourceObj.name) && isTextArea(sourceObj))
    { 
        var input = com.ebasetech.ufs.Main.findInput(sourceObj.name); 
        if (!com.ebasetech.ufs.Util.isUndefinedOrNull(input) && !com.ebasetech.ufs.Util.isUndefinedOrNull(input.firstInput)&& !com.ebasetech.ufs.Util.isUndefinedOrNull(input.validators)) 
        { 
            for&#40; var val = 0; val < input.validators.length; val++&#41;
            &#123;
                if&#40;!com.ebasetech.ufs.Util.isUndefinedOrNull&#40;input.validators&#91;val&#93;&#41; && !com.ebasetech.ufs.Util.isUndefinedOrNull&#40;input.validators&#91;val&#93;.fnct&#41; && input.validators&#91;val&#93;.fnct=="vldt.valMaxLength"&#41;
                &#123;
                    return input.validators&#91;val&#93;.property;
                &#125;
            &#125;
        &#125;
    &#125;
    return null; 
&#125;
           

function isTextArea&#40;sourceObj&#41;
&#123;
    if&#40;!com.ebasetech.ufs.Util.isUndefinedOrNull&#40;sourceObj&#41;&#41;
    &#123;
        return sourceObj.type == "textarea";
    &#125;
    return false;
&#125;
This is using Ebase internal structures as opposed to a published interface. The problem with doing this is that it may change in the future without notification - as is the case with the change from V3.4 to V4.5.
0 x

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

#3

Postby Jez » Tue Sep 20, 2016 11:41 am

Thanks Jon for the prompt response!

That's worked beautifully. :D

We would prefer to use a published API, but as this is not available, we will use this for now. Perhaps this will be included in the API at some point?
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC


Who is online

Users browsing this forum: No registered users and 23 guests