Thanks, Phillip --
This is something that has irked me for years. Due to its limitations, I've
never really used CFFORM extensively, but I thought I'd give it a go for a new
project and hit this immediately.
Your fix is great - if you control your own CF Server, but if you've got a
client who's on a shared box, then you need another work-around. My charming
husband has a solution:
So, you take the SERIOUSLY FLAWED CFSELECT-generated validation function
(called _CF_hasValue) and set it to a new variable, called _CF_hasValue_old.
Then, you run through your NEW function, now called by the original one's name.
If the function finds a select box of size 1 on the form, it will loop through
the values until it finds one that is not only SELECTED but also has a VALUE
(the latter little tidbit is NOT something that CF validation checks for.
Ridiculous!). If it finds one, it breaks out of the function. Otherwise, it
continues on and will returns false.
On the other hand, if the field in question isn't a single-select, then the old
CF Validating function will run.
** Caveat: this assumes that Adobe's not going to be changing the names of any
functions with newer versions... ?? So use at your own risk.
So, for example, I configured my form like this (using attribute
"queryposition" to manage my valueles OPTION tag relative to my query output):
<CFFORM... blah blah>
<CFSELECT name="ThingID" required="Yes" size="1" queryposition="below"
message="Please make a Thing selection."
value="ThingID" query="qThingTypes" display="Things">
<OPTION>Please select a Thing Type</OPTION>
</CFSELECT>
<[SUBMIT]>
</CFFORM>
<SCRIPT>
var _CF_hasValue_old = _CF_hasValue;
_CF_hasValue=function(_b,_c,_d)
{
if (_b.type == 'select-one')
{
var bSelected = false;
for (var i=0; i<_b.options.length; i++)
{
if (_b.options[i].selected == true &&
_b.options[i].value != '')
{
bSelected = true;
break;
}
}
return bSelected;
}
else
return _CF_hasValue_old(_b,_c,_d);
}
</SCRIPT>
==================================================================
> I just found this posted by a user in the LiveDocs and it works
> great!
>
> What you need to do is to edit the javascript that the CF server
> writes so that it also checks for a null value (your value="" part of
> your first option item). This is a simple code change in a javascript
> template file. Edit this file:
>
> C:\CFusionMX7\wwwroot\CFIDE\scripts\cfform.js
>
> Inside this file, modify line #73 this way:
>
> ORIGINAL:
> else if (obj_type == "SELECT")
> {
> for (i=0; i < obj.length; i++)
> {
> if (obj.options[i].selected)
> return true;
> }
> return false;
> }
>
> MODIFIED:
> else if (obj_type == "SELECT")
> {
> for (i=0; i < obj.length; i++)
> {
> if (obj.options[i].selected && obj.options[i].value != "")
> return true;
> }
> return false;
> }
>
> You may need to restart your coldfusion service, but otherwise this
> will work with the standard required="yes" method in your cfselect tag.
>
>
> Giving credit where credit is due:
> http://livedocs.macromedia.com/coldfusion/5.0/CFML_Reference/Tags91.
htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:304853
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4