Skip to content

Commit

Permalink
Handle case when you click input and immediately unclick
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Puczynski committed Dec 7, 2018
1 parent 1a1b6d2 commit b826b28
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/fields/ObjectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ class ObjectField extends Component {
getAvailableKey = (preferredKey, formData) => {
var index = 0;
var newKey = preferredKey;
while (this.props.formData.hasOwnProperty(newKey)) {
while (formData.hasOwnProperty(newKey)) {
newKey = `${preferredKey}-${++index}`;
}
return newKey;
};

onKeyChange = oldValue => {
return (value, errorSchema) => {
if (oldValue === value) {
return;
}
value = this.getAvailableKey(value, this.props.formData);
const newFormData = { ...this.props.formData };
const newKeys = { [oldValue]: value };
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function DefaultTemplate(props) {
<div className={classNames}>
{additional && (
<div className="form-group">
<Label label={keyLabel} required={required} />
<Label label={keyLabel} required={required} id={`${id}-key`} />
<LabelInput
label={label}
required={required}
Expand Down

0 comments on commit b826b28

Please sign in to comment.