Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Client side maxlength validation on CF 7 issue

New Here ,
May 21, 2009 May 21, 2009

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?

895
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2009 May 21, 2009

a maxlength attribute seems so much simpler.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 21, 2009 May 21, 2009

David,

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2009 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2009 May 21, 2009
LATEST

Validating at onBlur has a huge downside.  The user can still submit the form without changing the "bad" data.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources