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

Checkbox Control Help. Thanks! #4717

Closed
phpbits opened this issue Jan 28, 2018 · 8 comments
Closed

Checkbox Control Help. Thanks! #4717

phpbits opened this issue Jan 28, 2018 · 8 comments
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Question Questions about the design or development of the editor.

Comments

@phpbits
Copy link
Contributor

phpbits commented Jan 28, 2018

Just need help on how to your the checkbox field. I'm using

el(
				        CheckboxControl,
				        {
				            label: i18n.__( 'Desktop' ),
				            key: 'unique_key',
				            value: "1",
				            onChange: function( new_val ) {
				            	//need help here
				            },
				        },
			    	)

and I need help on how to set the checked value. Thanks!

@aduth
Copy link
Member

aduth commented Jan 28, 2018

You can refer to the React Forms documentation, which will apply the same for el. Specifically, you will want to use checked (a boolean value), not value, and your onChange handler should either set an attribute if it needs to be serialized within post content, or as a state value using the wp.components.withState helper if the value only needs to be stored temporarily while the user is editing.

@aduth aduth closed this as completed Jan 28, 2018
@aduth
Copy link
Member

aduth commented Jan 28, 2018

You can refer to the React Forms documentation, which will apply the same for el. Specifically, you will want to use checked (a boolean value), not value, and your onChange handler should either set an attribute if it needs to be serialized within post content, or as a state value using the wp.components.withState helper if the value only needs to be stored temporarily while the user is editing.

@aduth aduth added [Type] Question Questions about the design or development of the editor. [Feature] UI Components Impacts or related to the UI component system labels Jan 28, 2018
@phpbits
Copy link
Contributor Author

phpbits commented Jan 28, 2018

@aduth do you have docs for the fields? It will be easier to check the attributes available. Thanks!

@phpbits
Copy link
Contributor Author

phpbits commented Jan 28, 2018

@aduth It's probably similar to this issue : #4613 . And it's still open. Thanks!

@phpbits
Copy link
Contributor Author

phpbits commented Jan 29, 2018

Figured it out :) event.target.checked is what I'm looking for.

@aduth
Copy link
Member

aduth commented Jan 30, 2018

@phpbits You're correct this is related to #4613 . After #4720 is merged, the ToggleControl component will pass a boolean to onChange, not the event object. This will be reflected in the next plugin release of Gutenberg.

@phpbits
Copy link
Contributor Author

phpbits commented Jan 31, 2018

Thanks @aduth ! Would you mind checking this other issue I've posted : #4759 . Thanks!

@phpbits
Copy link
Contributor Author

phpbits commented Feb 1, 2018

@aduth Thank you very much for checking my other post. Would you mind checking this one too : #4723 (comment) . I can't seem to get a reply. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

2 participants