I just ran across this today. There is a bug with required checkboxes in CFMX7. Basically they don't work. However, you can get around this by simply writing your own validation using onSubmit. This is a known issue so no need to bug MACR about it. This code block demonstrates the bug:
<cfform format="flash">
<cfinput type="checkbox" name="agree" label="I Agree" required="true" value="1">
<cfinput type="submit" name="submit" value="Push the button">
</cfform>
<cfinput type="checkbox" name="agree" label="I Agree" required="true" value="1">
<cfinput type="submit" name="submit" value="Push the button">
</cfform>
And here is a sample of how to fix it:
<cfform format="flash" onSubmit="if(!agree.selected ){ alert('You must agree!'); return false; }">
<cfinput type="checkbox" name="agree" label="I Agree" required="true" value="1">
<cfinput type="submit" name="submit" value="Push the button">
</cfform>
<cfinput type="checkbox" name="agree" label="I Agree" required="true" value="1">
<cfinput type="submit" name="submit" value="Push the button">
</cfform>
Archived Comments
Very odd that this didn't get caught in the beta...In fact, very odd that most of the CFFORM bugs you found weren't fixed pre-release...
Well, from personal experience I can attest to the fact that MACR's QA for CF is very extensive. Obviously they can't catch everything though.
Excellent stuff once again Ray.
With checkboxes in CFFORM, the FORM fields contain true/false, not the 'value' if checked as with HTML forms.
Is there a way to get the value returned to the server?
OK... how about putting checkboxes in CFFormGroup sections? It seems they don't run for me there. I have changed the type to "radio" and the form loads, but if it is changed back to "checkbox" then it doesn't work. ARGHH... you would think I would have found opportunity to find that before they beta ended. Perhaps the guys on the beta could have verified it and then the update would have had a fix for that.
To be more specific... it's nested... inside a
CFForm "flash"...
CFFormGroup "Tab..." ...
CFFromGroup "page"
CFLoop query=""
And for some reason the flash doesn't come up... never loads but if the type is changed to radio then it works.
When you say they don't show up, you mean they just don't render? Can you post your full code, or a simpler version of it?
Got the issue figured out... WHEW!!! You cannot have two fields with the same name if they are checkbox type. In HTML you do this and it gives you back a list of all the checked items. Heh... should be labeled "DON'T TRY THIS IN FLASH FORMS". That took care of the issue just fine.
Thanks Ray- worked perfectly!
What if I have multiple checkboxes. Can this work?
I figured it out :
&& !hips.selected && !rcr.selected && !lab.selected && !bio.select