CFSELECT validation bug still exists in CF9

ColdFusion Add comments

A longstanding issue with CFSELECT still exists in CF9. For as long as CF has had CFFORM, there has been a bug in validating CFSELECT fields for required selections. It only looked to see if you had an option selected, but never checked to make sure that you had a value selected. So often we create a first option in a select box that has no value as a placeholder. According to CF, that's good enough to pass the required check if you just selected the placeholder. Adobe has been pinged on this issue by many developers over the years and still has failed to fix this for some reason.

There is a workaround for this though. When you use the required and validateat attributes of a CFINPUT, CFSELECT, or CFTEXTAREA, it pulls the front-end validation from CFIDE/scripts/cfform.js by default. Since this contains the incorrect method, you can do one of two things. You can edit the CFIDE/scripts/cfform.js file annd make the fix (it's extremely simple), or you can make a copy of that file, save it elsewhere, and access the file via the scriptsrc attribute of CFFORM.

The original fix for CF7 and CF8 can be found here: http://www.beetrootstreet.com/blog/index.cfm/2007/1/8/CFFORM-doesnt-catch-unselected-dropdown-lists-when-requiredtrue

The fix for CF9 is similar, you just need to make the following fix.

From:

if(_c=="SELECT"){
for(i=0;i<_b.length;i++){
if(_b.options[i].selected){
return true;
}

to:

if(_c=="SELECT"){
for(i=0;i<_b.length;i++){
if(_b.options[i].selected && _b.options[i].value !=''){
return true;
}
Comments are moderated solely for spam purposes.

0 responses to “CFSELECT validation bug still exists in CF9”

Leave a Reply

Leave this field empty:

Powered by Mango Blog. Design and Icons by N.Design Studio