How to use react-jsonschema-form - 10 common examples

To help you get started, we’ve selected a few react-jsonschema-form examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Talend / ui / packages / forms / src / deprecated / fields / ArrayField.js View on Github external
name,
			required,
			disabled,
			readonly,
			autofocus,
			registry,
			onBlur,
			onFocus,
		} = this.props;
		const title = schema.title || name;
		let items = this.props.formData;
		const { ArrayFieldTemplate, definitions, fields } = registry;
		const { TitleField } = fields;
		const itemSchemas = schema.items.map(item => retrieveSchema(item, definitions));
		const additionalSchema = allowAdditionalItems(schema)
			? retrieveSchema(schema.additionalItems, definitions)
			: null;
		const { addable = true } = getUiOptions(uiSchema);
		const canAdd = addable && additionalSchema;
		if (!items || items.length < itemSchemas.length) {
			// to make sure at least all fixed items are generated
			items = items || [];
			items = items.concat(new Array(itemSchemas.length - items.length));
		}

		// These are the props passed into the render function
		const arrayProps = {
			canAdd,
			className: 'field field-array field-array-fixed-items',
			disabled,
			idSchema,
			items: items.map((item, index) => {
github chili-epfl / collab-react-components / src / client / CollabForm.js View on Github external
function load() {
      switch (form.data.schema.type) {
        case 'string':
          // If the widget is not collaborative, we also have to update it !
          const { widget = 'text' } = getUiOptions(props.uiSchema);
          const isSupported = isAvailableWidget(widget);
          if (!isSupported) {
            this.setState({ form, isObject: false });
          } else {
            this.setState({ form, isObject: false, isCollab: true });
          }
          break;
        case 'object':
          // We save all non-collaborative keys
          const nonCollabKeys = [];
          const properties = form.data.schema.properties;
          Object.keys(properties).forEach(key => {
            if (properties[key].type !== 'string') {
              nonCollabKeys.push(key);
            } else if (props.uiSchema[key]) {
              // If the widget is not collaborative, we also have to update it ! Also if it is an enum
github cloudwan / gohan_webui / src / Form / formComponents / fields / ObjectField.js View on Github external
}
  // deep check on sorted keys
  if (!deepEquals(newKeys.sort(), oldKeys.sort())) {
    return true;
  }

  return false;
}

class ObjectField extends Component {
  nullValue = false;
  static defaultProps = {
    uiSchema: {},
    errorSchema: {},
    idSchema: {},
    registry: getDefaultRegistry(),
    required: false,
    disabled: false,
    readonly: false,
  };

  constructor(props) {
    super(props);

    this.state = {...this.getStateFromProps(props)};
    this.nullValue = props.formData === null || (this.isFieldEmpty() && !props.required);
  }

  componentWillReceiveProps(nextProps) {
    const state = this.getStateFromProps(nextProps);
    const {formData} = nextProps;
    if (formData && objectKeysHaveChanged(formData, this.state)) {
github cloudwan / gohan_webui / src / Form / formComponents / fields / BooleanField.js View on Github external
function buildOptions(schema, uiWidget) {
  // Note: uiWidget can be undefined, a string or an object; we only deal with
  // the inline option when we're provided a definition object.
  return {
    inline: isObject(uiWidget) &&
            isObject(uiWidget.options) &&
            uiWidget.options.inline,
    enumOptions: optionsList(Object.assign({
      enumNames: ['true', 'false'],
      enum: [true, false]
    }, {enumNames: schema.enumNames}))
  };
}
github rjsf-team / react-jsonschema-form / packages / material-ui / src / SelectWidget / SelectWidget.tsx View on Github external
const { type, items } = schema;
  if (value === '') {
    return undefined;
  } else if (type === 'array' && items && nums.has(items.type)) {
    return value.map(asNumber);
  } else if (type === 'boolean') {
    return value === 'true';
  } else if (type === 'number') {
    return asNumber(value);
  }

  // If type is undefined, but an enum is present, try and infer the type from
  // the enum values
  if (schema.enum) {
    if (schema.enum.every((x: any) => guessType(x) === 'number')) {
      return asNumber(value);
    } else if (schema.enum.every((x: any) => guessType(x) === 'boolean')) {
      return value === 'true';
    }
  }

  return value;
};
github cybertec-postgresql / rjsf-material-ui / src / SelectWidget / SelectWidget.tsx View on Github external
const { type, items } = schema;
  if (value === '') {
    return undefined;
  } else if (type === 'array' && items && nums.has(items.type)) {
    return value.map(asNumber);
  } else if (type === 'boolean') {
    return value === 'true';
  } else if (type === 'number') {
    return asNumber(value);
  }

  // If type is undefined, but an enum is present, try and infer the type from
  // the enum values
  if (schema.enum) {
    if (schema.enum.every((x: any) => guessType(x) === 'number')) {
      return asNumber(value);
    } else if (schema.enum.every((x: any) => guessType(x) === 'boolean')) {
      return value === 'true';
    }
  }

  return value;
};
github rjsf-team / react-jsonschema-form / packages / material-ui / src / SelectWidget / SelectWidget.tsx View on Github external
const processValue = (schema: any, value: any) => {
  // "enum" is a reserved word, so only "type" and "items" can be destructured
  const { type, items } = schema;
  if (value === '') {
    return undefined;
  } else if (type === 'array' && items && nums.has(items.type)) {
    return value.map(asNumber);
  } else if (type === 'boolean') {
    return value === 'true';
  } else if (type === 'number') {
    return asNumber(value);
  }

  // If type is undefined, but an enum is present, try and infer the type from
  // the enum values
  if (schema.enum) {
    if (schema.enum.every((x: any) => guessType(x) === 'number')) {
      return asNumber(value);
    } else if (schema.enum.every((x: any) => guessType(x) === 'boolean')) {
      return value === 'true';
    }
  }

  return value;
};
github cloudwan / gohan_webui / src / Form / formComponents / fields / ObjectField.js View on Github external
function objectKeysHaveChanged(formData, state) {
  // for performance, first check for lengths
  const newKeys = Object.keys(formData);
  const oldKeys = Object.keys(state);
  if (newKeys.length < oldKeys.length) {
    return true;
  }
  // deep check on sorted keys
  if (!deepEquals(newKeys.sort(), oldKeys.sort())) {
    return true;
  }

  return false;
}
github cloudwan / gohan_webui / src / Form / formComponents / fields / ArrayField / ArrayField.js View on Github external
uiSchema,
      errorSchema,
      idSchema,
      name,
      required,
      disabled,
      readonly,
      autofocus,
    } = this.props;
    const title = schema.title || name;
    let {items} = this.state;
    const {definitions, fields} = this.props.registry;
    const {TitleField} = fields;
    const itemSchemas = schema.items.map(item =>
      retrieveSchema(item, definitions));
    const additionalSchema = allowAdditionalItems(schema) ?
      retrieveSchema(schema.additionalItems, definitions) : null;

    if (!items || items.length < itemSchemas.length) {
      // to make sure at least all fixed items are generated
      items = items || [];
      items = items.concat(new Array(itemSchemas.length - items.length));
    }

    return (
      <fieldset>
        
        {schema.description ?</fieldset>
github Talend / ui / packages / forms / src / deprecated / fields / ArrayField.js View on Github external
idSchema,
			name,
			required,
			disabled,
			readonly,
			autofocus,
			registry,
			onBlur,
			onFocus,
		} = this.props;
		const title = schema.title || name;
		let items = this.props.formData;
		const { ArrayFieldTemplate, definitions, fields } = registry;
		const { TitleField } = fields;
		const itemSchemas = schema.items.map(item =&gt; retrieveSchema(item, definitions));
		const additionalSchema = allowAdditionalItems(schema)
			? retrieveSchema(schema.additionalItems, definitions)
			: null;
		const { addable = true } = getUiOptions(uiSchema);
		const canAdd = addable &amp;&amp; additionalSchema;
		if (!items || items.length &lt; itemSchemas.length) {
			// to make sure at least all fixed items are generated
			items = items || [];
			items = items.concat(new Array(itemSchemas.length - items.length));
		}

		// These are the props passed into the render function
		const arrayProps = {
			canAdd,
			className: 'field field-array field-array-fixed-items',
			disabled,
			idSchema,