Skip to content

add DidUpdate support to typeahead #148

@WpSlt

Description

@WpSlt

I would like to propose to add DidUpdate support to your typeahead field.
Somenthing like it:

function isValidOptions(options) {
  return !!options && options.constructor === Array;
}

export class AsyncTypeaheadField extends BaseTypeaheadField {
  constructor(props) {
    super(props);

    let { schema, uiSchema: { asyncTypeahead }, formData } = this.props;

    this.state = {
      options: isValidOptions(asyncTypeahead.options) ? asyncTypeahead.options : [],
      isLoading: false,
      selected: isValidFormData(formData)
        ? toSelected(formData, schema, asyncTypeahead.mapping, asyncTypeahead.options)
        : [],
    };
  }

	componentDidUpdate(prevProps, prevState) {
	  if (this.props.uiSchema !== prevProps.uiSchema) {
		let { schema, uiSchema: { asyncTypeahead }, formData} = this.props;

		this.setState({
		  options: isValidOptions(asyncTypeahead.options) ? asyncTypeahead.options : [],
		  isLoading: false,
		  selected: isValidFormData(formData)
			? toSelected(formData, schema, asyncTypeahead.mapping, asyncTypeahead.options)
			: [],
		});
	  }
	}
....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions