radioButton()
Generates an HTML radio button for a form, based on a model object’s property. It can handle simple properties as well as nested properties through associations, making it ideal for forms that work with both individual objects and collections. You can customize the radio button with additional attributes, labels, and error handling options. It automatically reflects the object’s current property value, so if the property matches the tagValue, the radio button will be marked as checked. This function helps you build dynamic forms safely and easily, with support for encoding to prevent XSS attacks, error highlighting, and custom HTML wrapping. Note: Pass any additional arguments like class, rel, and id, and the generated tag will also include those values as HTML attributes.
1. Basic radio buttons for gender
<cfoutput>
<fieldset>
<legend>Gender</legend>
#radioButton(objectName="user", property="gender", tagValue="m", label="Male")#<br>
#radioButton(objectName="user", property="gender", tagValue="f", label="Female")#
</fieldset>
</cfoutput>
2. Radio buttons for nested association (committee members)
<cfoutput>
<cfloop from="1" to="#ArrayLen(committee.members)#" index="i">
<div>
<h3>#committee.members[i].fullName#:</h3>
<div>
#radioButton(
objectName="committee",
association="members",
position=i,
property="gender",
tagValue="m",
label="Male"
)#<br>
#radioButton(
objectName="committee",
association="members",
position=i,
property="gender",
tagValue="f",
label="Female"
)#
</div>
</div>
</cfloop>
</cfoutput>
3. Custom HTML wrapping and label placement
#radioButton(
objectName="user",
property="subscription",
tagValue="premium",
label="Premium Plan",
prepend="<div class='radio-wrapper'>",
append="</div>",
labelPlacement="aroundRight"
)#