Commit 7a354846 authored by Matija Obreza's avatar Matija Obreza

Merge branch '564-user-can-apply-incorrect-inscodes-if-he-use-copy-paste' into 'master'

Fix: User can apply incorrect insCodes if he use copy-paste

Closes #564

See merge request genesys-pgr/genesys-ui!559
parents 774898ee b981cd4f
......@@ -254,12 +254,45 @@ class AutocompleteFilterInternal extends React.Component<IAutocompleteFilterInte
private dataPasted = (e) => {
const data = e.clipboardData.getData('text/plain');
const dataArr = data.split(/[,\n;]/).map((item) => item.trim());
const { validators } = this.props;
if (dataArr && dataArr.length > 1) {
e.preventDefault();
const values = this.maybeAdd(...dataArr);
const { input } = _.get(this.props, this.props.names[0]);
input.onChange(values);
e.preventDefault();
let values = this.maybeAdd(...dataArr);
const {input} = _.get(this.props, this.props.names[0]);
if (validators && validators.length !== 0) {
const errors = [];
validators.forEach((validator) => {
values = values.filter((value) => {
if (validator(value)) {
errors.push(validator(value));
return false
} else {
return true;
}
});
});
if (errors.length !== 0) {
if (input.value && input.value.length !== 0) {
const unique = [...new Set([...input.value, ...values])];
input.onChange('');
this.setState({
text: '',
values: unique,
excludedValues: unique,
});
input.onChange(unique);
return;
}
if (values.length === 0) {
input.onChange('');
return;
}
}
}
input.onChange(values);
}
}
private onKeyPress = (e, data, autocompleteInput, that) => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment