Closed johnament closed 2 years ago
@johnament In your example, in the custom field you used onChange from the schema object, but in the documentation show that onChange comes directly from the properties
import Select from 'react-select' // and others ommitted
class SelectionField extends Component {
static propTypes = {
schema: PropTypes.object,
onChange: PropTypes.func,
id: PropTypes.string.isRequired
}
render () {
return (
<Select
id={this.props.id}
ref={(ref) => { this.select = ref }}
onBlurResetsInput={false}
onSelectResetsInput={false}
options={this.props.schema.values}
simpleValue
clearable={this.props.schema.clearable}
name={this.props.id}
disabled={this.props.schema.disabled}
value={this.props.schema.selectedValue}
onChange={this.props.onChange}
rtl={this.props.schema.rtl}
searchable={this.props.schema.searchable}
/>
)
}
}
@miguelcast thanks for the hint. I got something working. I did end up writing a local onChange
function that sets the value and state (ensuring that the right state causes the component to keep track of the value). That onChange
is delegating back to this.props.onChange
which is the important step; since that causes the event to fire in the parent form.
Which documentation are you referring to?
This is of part documentation Custom widget components.
Prerequisites
Description
First, I want to say that this is an awesome component. In the same time that I used to be able to spin up a JSF page that did CRUD, I could do as well with this component. Kudos to you guys!
I'm creating a simple wrapper for
react-select
to be used within a form. My component's pretty straight forward:In my form, I import this and mention it as a UI Widget:
I noticed at this point, my
Form.onChange
function isn't being called. This happens even when I don't pass in aonChange
reference to the field. This is how my field is eventually defined:For completeness, this is what my
onChange
andsetField
functions look like, in addition to the final renderIt could be that this is expected, however, because the Form's
onChange
doesn't get invoked, the underlying formData object doesn't get updated.Steps to Reproduce
Ideally, I'm providing a sample JSFiddle or a shared playground link demonstrating the issue.
Expected behavior
The form's
onChange
is invokedActual behavior
The field's
onChange
gets invoked (by the underlying component), but the form'sonChange
does not get invoked.Version
1.0.1