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
More elaborate example of using Custom Form components? #10
Comments
This is the custom picker let's say, I want to be able to access the |
The selected value always come from top, so use props instead of state, like this: export default class EmojiStrip extends Component {
constructor(props) {
super(props);
this.emojis = ['smiley', 'neutral_face', 'disappointed', 'x'];
}
static defaultProps = {
selected: 'hello',
onSelectEmoji: () => {}
};
isEmojiSelected = (emoji) => {
if (this.props.selected === emoji) {
return true;
}
return false;
}
renderEmojis = () => this.emojis.map((emoji, index) =>
<Emoji
key={index}
emoji={emoji}
enabled={this.isEmojiSelected(emoji)}
onSelectEmoji={this.props.onSelectEmoji}
/>
);
render() {
return (
<View style={styles.container}>
{
this.renderEmojis()
}
</View>
);
}
} Define the emoji custom field: var customFields = {
'EmojiStrip': {
controlled: true,
valueProp: 'selected',
callbackProp: 'onSelectEmoji',
}
}
<Form ref="form" customFields={customFields}>
<EmojiStrip type="EmojiStrip" name="emoji" selected="smiley" />
</Form> Get the value: this.refs.form.getValues().emoji |
I got it now :), So I shouldn't control the selected value myself instead let the |
There's another problem now, unless |
Can you paste your code here? |
PracticeDetails is the parent which will hold multiple custom form fields. |
Yeah.. We only have support for deep elements if they are form's direct children, but you can do something like this: https://gist.github.com/julianocomg/125c25b985fe8e3e2b773316171fad9d Or maybe you can put a |
The first approach works. Thank you 👍 |
What properties are required in the customFields object? I was hoping to use this component to get the value of a custom picker. The picker has a state property called
selected
which is the value of this picker. How should I go about implementing this functionality?The text was updated successfully, but these errors were encountered: