Skip to:
Content

BuddyPress.org

Opened 5 years ago

Closed 5 years ago

#6751 closed enhancement (fixed)

Extended profile checkbox defaults are overly enthusiastic.

Reported by: dcavins Owned by: dcavins
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.4.0
Component: Extended Profile Keywords: has-patch
Cc: dcavins

Description

If there's a default value set for a checkbox, it is pre-selected when users first encounter the form. (That seems good.) But if a user selects none of the options so that an empty array is saved to the db, then every time the user edits that profile field group, the default option is pre-selected again. Like the form is saying "Are you SURE you don't want to pick this option?"

I've attached a patch that attempts to differentiate one null value from another by checking the return value type from BP_XProfile_ProfileData::get_value_byid(), which appears to return an empty array if there is a saved value that is empty (no options selected) vs an empty string if no value exists for that field/user combination.

Attachments (2)

6751.01.patch (1.6 KB) - added by dcavins 5 years ago.
Differentiate when the user has selected none of the options versus when the user has not yet saved a value for this field.
6751.02.patch (1.8 KB) - added by dcavins 5 years ago.

Download all attachments as: .zip

Change History (7)

@dcavins
5 years ago

Differentiate when the user has selected none of the options versus when the user has not yet saved a value for this field.

#1 @boonebgorges
5 years ago

  • Milestone changed from Awaiting Review to 2.5
  • Owner set to dcavins
  • Status changed from new to assigned

Approach looks good to me. Tiny nitpick: multiline inline comments should look like

/*
 * Foo bar.
 *
 * Note the single (not double) asterisk on the first line of the comment.
 */

https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#5-2-multi-line-comments

#2 @dcavins
5 years ago

Thanks for looking this over @boonebgorges. Does it make sense to apply similar logic to non-required radio button groups? (There's some extra logic for radio buttons if they're required fields.)

As is, if a user clicks "clear" on a radio button group then saves the form, when the form reloads, the default is pre-selected all over again. I'm guessing that if the radio group is required, and no option is selected, the default should be selected.

#3 @boonebgorges
5 years ago

As is, if a user clicks "clear" on a radio button group then saves the form, when the form reloads, the default is pre-selected all over again. I'm guessing that if the radio group is required, and no option is selected, the default should be selected.

Yeah, this seems correct to me. We shouldn't be allowing null radio buttons.

#4 @dcavins
5 years ago

I've updated the patch to include better comments

I also explored adding a similar check to radio buttons. Unfortunately, the radio button save routine removes the corresponding wp_bp_xprofile_data row if no option is selected, so there's no way I can think of to separate intentionally empty values from the case where no value has been set yet. When you edit a profile field group with radio buttons, you'll either need to select one or click "clear" to renew your abstention every time you fill out the form.

I'll let this patch float a few days then commit it. Thanks again for your feedback.

@dcavins
5 years ago

#5 @dcavins
5 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 10561:

Profile checkboxes: Allow users to select none.

Previously, the default option was pre-selected
whether the user had never completed the
checkbox field or the user had selected none.
This changeset differentiates the null values and
respects a user's none-of-the-above choice.

Fixes #6751.

Note: See TracTickets for help on using tickets.