Skip to content

Commit

Permalink
Fix JSON paste error handling (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Dec 26, 2016
1 parent 6726a9b commit 2163d2a
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/internal-packages/crud/lib/component/editable-value.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,40 @@ class EditableValue extends React.Component {
handleChange(evt) {
const value = evt.target.value;
if (this._pasting) {
this._pasteEdit(value);
} else {
this._typeEdit(value);
}
}

/**
* Edit as if typing.
*
* @param {String} value - The value.
*/
_typeEdit(value) {
this._node.size = inputSize(value);
const currentType = this.element.currentType;
const castableTypes = TypeChecker.castableTypes(value, this.isHighPrecision());
if (_.includes(castableTypes, currentType)) {
this.element.edit(TypeChecker.cast(value, currentType));
} else {
this.element.edit(TypeChecker.cast(value, castableTypes[0]));
}
}

/**
* Edit the field value when using copy/paste.
*
* @param {String} value - The value to paste in.
*/
_pasteEdit(value) {
try {
this.element.bulkEdit(value);
} catch (e) {
this._typeEdit(value);
} finally {
this._pasting = false;
} else {
this._node.size = inputSize(value);
const currentType = this.element.currentType;
const castableTypes = TypeChecker.castableTypes(value, this.isHighPrecision());
if (_.includes(castableTypes, currentType)) {
this.element.edit(TypeChecker.cast(value, currentType));
} else {
this.element.edit(TypeChecker.cast(value, castableTypes[0]));
}
}
}

Expand Down

0 comments on commit 2163d2a

Please sign in to comment.