Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add selected attribute to specific options in a checkbox group. #8

Open
richardsweeney opened this issue Jan 16, 2014 · 4 comments
Assignees

Comments

@richardsweeney
Copy link

I can create a checkbox group like so:

$checkboxes = WP_Form_Element::create( 'checkboxes' )
    ->set_name( 'interests' )
    ->set_label( 'Interests' )
    ->add_option( 'something,'Something' )
    ->add_option( 'something_else', Something else' );

Cool.

But if I'm grabbing data from the database (after the form has been submitted), how do I show which options have been selected.

$checkboxes->set_attribute( 'checked', 'checked' );

Will sets all the attributes to checked. There doesn't seem to be anything I can find in the docs about this. Any tips!?

@jbrinley
Copy link
Owner

You should be able to use $checkboxes->set_default_value(array('something'));, just as you do with select boxes. But quickly skimming the code in WP_Form_View_Checkboxes, it looks like I haven't yet implemented that. I'll add it in as soon as I can (but I'm a little overwhelmed right now, so pull requests are always welcome).

@ghost ghost assigned jbrinley Jan 16, 2014
@richardsweeney
Copy link
Author

Cool. I'll take a look and see if I can fix this myself. It's such a fantastic project I'd love to contribute if I can :)

@dentm42
Copy link

dentm42 commented Jan 16, 2015

Richard - THANK YOU for the update! I was pulling my hair out for a bit.

In case anyone else needs this fixed - see Richard's pull request:

#9

@korobochkin
Copy link

Oh. I tried to solved this on the past week but can't create a pretty working solution and now I find this. You rock @richardsweeney. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants