Skip to main content
Participating Frequently
May 21, 2009
Question

Client side maxlength validation on CF 7 issue

  • May 21, 2009
  • 2 replies
  • 964 views

I'm working on a customer site running on CF7 on Solaris and am doing a down-and-dirty addition of form field validation and wanted to use cfinput validation. The following attempt to use maxlength:

<cfinput name="FIRST_NAME" type="text" id="First_Name"
     size="35" value="#session.stItem.FIRST_NAME#" validate="maxlength"
     message="This field can only be 5 characters long."
     validateAt="onBlur" maxLength="15" />

causes a JS error box whenever anything is entered into the field. The code it generates on the field is:

onblur="if( ( this.value.length > null) ){ _CF_onErrorAlert(new Array('This field can only be 5 characters long.')); }"

which makes no sense.

If I add in the required attribute, it gets worse -- doing an AND when an OR should have been done. So

<cfinput name="FIRST_NAME" type="text" id="First_Name"
     size="35" value="#session.stItem.FIRST_NAME#" validate="maxlength"
     required="yes"
     message="This field can only be 5 characters long."
     validateAt="onBlur" maxLength="15" />

produces the following code:

onblur="if( !_CF_hasValue(this, 'TEXT', false) && ( this.value.length > null) ){ _CF_onErrorAlert(new Array('This field can only be 5 characters long.')); }"

I've googled for info on the above, but didn't find anything. Is there a known bug on this or am I missing something?

    This topic has been closed for replies.

    2 replies

    Inspiring
    May 21, 2009

    David,

    If you change the validateAt attribute from onBlur to onSubmit (the default), does it change the resulting JS error?

    Participating Frequently
    May 21, 2009

    Interestingly, the JS code seems to be right -- it generates:

            //form element FIRST_NAME 'MAXLENGTH' validation checks
            if( _CF_this['FIRST_NAME'].value.length > 15 )
            {
                _CF_onError(_CF_this, "FIRST_NAME", _CF_this['FIRST_NAME'].value, "This field can only be 15 characters long.");
                _CF_error_exists = true;

            }

    which looks right. I can probably live with it being onsubmit but it would be nice to have the option to check at entry time.

    d

    Inspiring
    May 21, 2009

    a maxlength attribute seems so much simpler.