-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Enable Arrays to be marked as required, and fixes for strings marked as required #442
Changes from 3 commits
c30f5b4
cc91fa2
8ecafc2
5091525
8e2ecf1
e0fe72e
b826fc8
2e3c712
477d7de
ea934ed
fe28e93
5f15775
7e7a925
4026366
0e05f7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,8 +216,12 @@ class ArrayField extends Component { | |
if (event) { | ||
event.preventDefault(); | ||
} | ||
var newitems = this.state.items.filter((_, i) => i !== index); | ||
if (newitems.length == 0) { | ||
newitems = undefined; | ||
} | ||
this.asyncSetState({ | ||
items: this.state.items.filter((_, i) => i !== index) | ||
items: newitems | ||
}, {validate: true}); // refs #195 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const items = this.state.items.filter((_, i) => i !== index);
this.asyncSetState({
items: items.length > 0 ? items : undefined,
}, {validate: true}); // refs #195 |
||
}; | ||
}; | ||
|
@@ -327,7 +331,7 @@ class ArrayField extends Component { | |
} | ||
|
||
renderMultiSelect() { | ||
const {schema, idSchema, uiSchema, disabled, readonly, autofocus} = this.props; | ||
const {schema, idSchema, uiSchema, disabled, required, readonly, autofocus} = this.props; | ||
const {items} = this.state; | ||
const {widgets, definitions} = this.props.registry; | ||
const itemsSchema = retrieveSchema(schema.items, definitions); | ||
|
@@ -338,6 +342,7 @@ class ArrayField extends Component { | |
<Widget | ||
id={idSchema && idSchema.$id} | ||
multiple | ||
required={required} | ||
onChange={this.onSelectChange} | ||
options={options} | ||
schema={schema} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,21 +8,25 @@ function BaseInput(props) { | |
value, | ||
readonly, | ||
autofocus, | ||
onChange, | ||
options, // eslint-disable-line | ||
schema, // eslint-disable-line | ||
formContext, // eslint-disable-line | ||
registry, // eslint-disable-line | ||
...inputProps | ||
} = props; | ||
const _onChange = props.onChange; | ||
return ( | ||
<input | ||
{...inputProps} | ||
className="form-control" | ||
readOnly={readonly} | ||
autoFocus={autofocus} | ||
value={typeof value === "undefined" ? "" : value} | ||
onChange={(event) => onChange(event.target.value)}/> | ||
onChange={(event) => {if (event.target.value == "") { | ||
return _onChange(undefined); | ||
} else { | ||
return _onChange(event.target.value); | ||
}}}/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const _onChange = ({target: {value}}) => {
return props.onChange(value === "" ? undefined : value);
};
// ...
onChange={_onChange} /> |
||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,12 @@ function selectValue(value, selected, all) { | |
} | ||
|
||
function deselectValue(value, selected) { | ||
return selected.filter(v => v !== value); | ||
var ret = selected.filter(v => v !== value); | ||
if (ret.length == 0) { | ||
return undefined; | ||
} else { | ||
return ret; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const ret = selected.filter(v => v !== value);
return ret.length === 0 ? undefined : ret; |
||
} | ||
|
||
function CheckboxesWidget(props) { | ||
|
@@ -19,7 +24,7 @@ function CheckboxesWidget(props) { | |
return ( | ||
<div className="checkboxes" id={id}>{ | ||
enumOptions.map((option, index) => { | ||
const checked = value.indexOf(option.value) !== -1; | ||
const checked = (value === undefined) ? false : value.indexOf(option.value) !== -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Unnecessary wrapping parenthesis. |
||
const disabledCls = disabled ? "disabled" : ""; | ||
const checkbox = ( | ||
<span> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ function TextareaWidget({ | |
autofocus, | ||
onChange | ||
}) { | ||
const _onChange = onChange; | ||
return ( | ||
<textarea | ||
id={id} | ||
|
@@ -22,7 +23,11 @@ function TextareaWidget({ | |
disabled={disabled} | ||
readOnly={readonly} | ||
autoFocus={autofocus} | ||
onChange={(event) => onChange(event.target.value)}/> | ||
onChange={(event) => {if (event.target.value == "") { | ||
return _onChange(undefined); | ||
} else { | ||
return _onChange(event.target.value); | ||
}}}/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous impl. suggestion above. |
||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to maked? Looks like a typo. Maybe "to mark"?