question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use radio button with React Native & Native Base

See original GitHub issue

Hi, I want to use Redux Form with React Native and Native Base but I’m having trouble with rendering a radio button in my app and I was hoping that someone can guide me into right direction for it.

renderRadio({ input, type, options, meta: { touched, error } }) {
    const hasError = touched && error;
    return (
      <Form>
        <Grid>
          <Row>
            {options.map(o => <Item key={o.value}>
              <FontAwesome name={o.value === "M" ? "male" : "female"} size={25}/>
              <Label>{o.title}</Label>
              <Input {...input} type={type} value={o.value} checked={o.value === input.value}/>
              {hasError && <Text>{error}</Text>}
            </Item>)}
          </Row>
        </Grid>
      </Form>
    );
  }

render() {
    const { handleSubmit, fields: { email, password, passwordConfirm, gender } } = this.props;
    return (
      <Container style={styles.container}>
        <Content>
          <Form>
            <Field name="email" component={this.renderField} label="Email"/>
            <Field name="password" component={this.renderField} label="Password"/>
            <Field name="passwordConfirm" component={this.renderField} label="Password Confirm"/>
            <Field name="gender" type="radio" component={this.renderRadio} options={[
                {title: 'Male', value: "M"},
                {title: 'Female', value: "F"}
              ]}/>
            {this.renderAlert()}
            <Button
              style={styles.button} block
              action="submit"
              onPress={handleSubmit(this.handleFormSubmit.bind(this))}
            >
              <Text>Signup</Text>
            </Button>
          </Form>
        </Content>
      </Container>
    );
  }

In my code, I do not see any type of radio button (neither any check sign) and get my input value from renderRadio method as undefined. screen shot 2017-06-05 at 3 56 53 pm

Can anyone please help me with this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
sophieewscommented, Aug 12, 2018

I’m not sure if this helps with the radio button but I got the Native Base checkbox working using

const renderCheckBox = ({ input, checked, label, meta: {touched, error}, children, ...custom }) => (
    <CheckBox
        checked={input.value}
        onPress={() => {
            input.value ? input.value = false: input.value = true;
            input.onChange(input.value)
        }}
        {...custom}
    />
);
1reaction
gustavohenkecommented, Jun 19, 2017

Hi @ckim16, this is a tricky one. See #2292 why.

When you use a <Field type="radio" />, Redux Form requires that you set value too. So you are basically not allowed to have a radio group this way; either remove the type or spread the radios in the component that will render them.

Example: https://codesandbox.io/s/EkggLy6m

Read more comments on GitHub >

github_iconTop Results From Across the Web

Radio Button
Radio Button | NativeBase | Universal Components for React and React Native · In v3 Radio can only used along with Radio. ·...
Read more >
Radio buttons are not working in Native-Base
I need to use radio buttons, but they don't work. When you click nothing happens. Here is the code. import React, { Component...
Read more >
Create and customize radio buttons in React Native
Learn how to build a radio button form using the React Native library and customize your radio elements for a decorated form.
Read more >
native-base-docs/RadioButton.md at master
Radio Button. Radio buttons let the user select any one from a set of options. Replacing Component: React Native TouchableOpacity · Preview ios...
Read more >
Radio Button · NativeBase for Web
Radio Button ; import React, { Component } from ; 'react'; import ; from 'native-base' ; export default ; class RadioButtonExample extends Component...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found