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

Support checkboxes #27

Closed
ezhlobo opened this issue Nov 11, 2016 · 3 comments
Closed

Support checkboxes #27

ezhlobo opened this issue Nov 11, 2016 · 3 comments

Comments

@ezhlobo
Copy link

ezhlobo commented Nov 11, 2016

Hi! I have a problem with setting up checkboxes inside formous. What's the best way to do it?

Now I have to do something like this:

<Checkbox
  checked={this.state.rememberMeValue}
  onBlur={(event) => {
    event.target.value = this.state.rememberMeValue;
    rememberMe.events.onBlur(event);
  }}
  onChange={(event) => {
    this.setState({ rememberMeValue: !this.state.rememberMeValue });
    event.target.value = this.state.rememberMeValue;
    rememberMe.events.onChange(event);
  }}
>
  Remember me
</Checkbox>

I guess checkboxes aren't supported by formous, are they?

@jhsu
Copy link
Contributor

jhsu commented Nov 11, 2016

@ezhlobo with a checkbox onChange, you can access the event.target.checked property to see if it is checked, so you could translate that to the value

for example if your field name in formous is rememberMe:

<input
  type="checkbox"
  checked={this.props.fields.rememberMe.value}
  onChange={(event) => {
    this.props.fields.rememberMe.events.onChange({
      target: { value: event.target.checked }
    });
  }}
  >
  Remember me
</input>

and you could pull it to some helper function:

function onCheckedHandler(field) {
  return function(event) {
    field.events.onChange({
      target: { value: event.target.checked }
    });
  };
}

// and using it
<input
  type="checkbox"
  checked={this.props.fields.rememberMe.value}
  onChange={onCheckedHandler(this.props.fields.rememberMe)}
  >
  Remember me
</input>

@ffxsam
Copy link
Owner

ffxsam commented Nov 11, 2016

@ezhlobo I realize support for checkboxes and radios is not great.. or even present. We're on a temporary code freeze for now, but it'll get addressed during the rewrite.

@ezhlobo
Copy link
Author

ezhlobo commented Nov 11, 2016

@ffxsam thank you, I understood!

@jhsu Yeah I've did the same trick to make rememberMe workable I just thought that there is any good solution which I can't find in documentation.

@ezhlobo ezhlobo closed this as completed Nov 11, 2016
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

3 participants