Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
render() {
const { schema, uiSchema, idSchema, registry } = this.props;
const { definitions } = registry;
// eslint-disable-next-line no-prototype-builtins
if (!schema.hasOwnProperty('items')) {
return (
);
}
if (isFixedItems(schema)) {
return this.renderFixedArray();
}
if (isFilesArray(schema, uiSchema, definitions)) {
return this.renderFiles();
}
if (isMultiSelect(schema, definitions)) {
return this.renderMultiSelect();
}
return this.renderNormalArray();
}
}
componentDidMount() {
const {initialItem} = {initialItem: true, ...this.props.uiSchema['ui:options']};
if (initialItem) {
const {items} = this.state;
const {schema, registry} = this.props;
const {definitions} = registry;
let itemSchema = schema.items;
if (isFixedItems(schema) && allowAdditionalItems(schema)) {
itemSchema = schema.additionalItems;
}
if (isEmpty(items) && this.props.required) {
this.props.onChange(items.concat([
getDefaultFormState(itemSchema, undefined, definitions)
]), {validate: false});
}
}
}
onAddClick(event) {
event.preventDefault();
const { schema, formData, registry } = this.props;
const { definitions } = registry;
let itemSchema = schema.items;
if (isFixedItems(schema) && allowAdditionalItems(schema)) {
itemSchema = schema.additionalItems;
}
formData.forEach(item => Object.assign(item, { isClosed: true }));
this.props.onChange([...formData, getDefaultFormState(itemSchema, undefined, definitions)], {
validate: false,
});
}
onAddClick = event => {
event.preventDefault();
const {items} = this.state;
const {schema, registry} = this.props;
const {definitions} = registry;
let itemSchema = schema.items;
if (isFixedItems(schema) && allowAdditionalItems(schema)) {
itemSchema = schema.additionalItems;
}
const newItems = items.concat([
getDefaultFormState(itemSchema, undefined, definitions)
]);
this.asyncSetState({
items: newItems,
selectedTabId: newItems.length - 1
});
};
render() {
const {schema, uiSchema} = this.props;
const widget = uiSchema['ui:widget'];
if (widget === 'hidden') {
return null;
}
if (isFilesArray(schema, uiSchema)) {
return this.renderFiles();
}
if (isFixedItems(schema)) {
return this.renderFixedArray();
}
if (isMultiSelect(schema)) {
return this.renderMultiSelect();
}
if (schema.items.type === 'object') {
return this.renderObjectArray();
}
return this.renderNormalArray();
}