Re: Radio button aggressively resets to global default in edit field
I think the following properly displays the output from bp_get_the_profile_field_options() as an example of when radio-buttons intermittently display incorrectly. Below that I also show a potential fix – although @jeffsayre or another BP-expert may have a better solution. (Thanks @hnla for explanation)
<div id="field_125"><label><input checked="checked" type="radio" name="field_125" id="option_126" value="Professional">
Professional</label>
<label><input type="radio" name="field_125" id="option_127" value="Organizational">Organizational</label>
<label><input checked="checked" type="radio" name="field_125" id="option_128" value="Standard">Standard</label>
<label><input type="radio" name="field_125" id="option_129" value="Volunteer">Volunteer</label>
<label><input type="radio" name="field_125" id="option_130" value="Student">Student</label></div>
Notice that there are TWO checked=”checked” settings in the list. This occurs in the ‘radio’ switch statement of bp_get_the_profile_field_options() because of an IF-statement within a for-loop that I believe too liberally assigns the “checked” value to the default-value in the list regardless of whether or not there is already a set-value.
One alternative is to assign a variable before the for-loop…
$SomeValueChecked = FALSE;
… then check this variable within the IF-stmt before setting the default-value. Something like the following:
if ( $option_value == $options[$k]->name || $value == $options[$k]->name || ( $options[$k]->is_default_option && $SomeValueChecked == FALSE ) ) {
$SomeValueChecked = TRUE;
$selected = ' checked="checked"';
}