Validate on change, not on switch

This commit is contained in:
Ilya Ig. Petrov 2017-06-17 20:43:08 +05:00
parent 2c3c36c643
commit 3e170fc7f4

View File

@ -366,11 +366,15 @@ export default function getProxyEditor(theState) {
super(props); super(props);
this.state = getInitState(); this.state = getInitState();
this.resetState = linkEvent(this, this.resetState);
} }
resetState(that, event) { resetState(that, event) {
if (that.state.ifHasErrors) {
that.props.funs.setStatusTo(''); // Clear errors
}
that.setState(getInitState()); that.setState(getInitState());
event.preventDefault(); event.preventDefault();
@ -417,28 +421,32 @@ export default function getProxyEditor(theState) {
handleModeSwitch(that, event) { handleModeSwitch(that, event) {
if (that.state.stashedExports !== false) { console.log('SWITCH!');
const errors = that.getErrorsInStashedExports(); if (that.state.ifHasErrors) {
if (errors) { return;
that.setState({ifHasErrors: true});
that.props.funs.showErrors(...errors);
return;
}
that.props.setProxyStringRaw(that.state.stashedExports);
} }
that.setState({
stashedExports: false,
ifHasErrors: false,
});
that.props.onSwitch(); that.props.onSwitch();
} }
handleTextareaChange(that, event) { handleTextareaChange(that, event) {
console.log('CHANGE!');
that.setState({ that.setState({
stashedExports: normalizeProxyString(event.target.value), stashedExports: normalizeProxyString(event.target.value),
}); });
const errors = that.getErrorsInStashedExports();
if (errors) {
that.setState({ifHasErrors: true});
that.props.funs.showErrors(...errors);
return;
}
// No errors.
that.props.setProxyStringRaw(that.state.stashedExports);
that.setState({
stashedExports: false,
ifHasErrors: false,
});
} }
@ -451,8 +459,6 @@ export default function getProxyEditor(theState) {
render(props) { render(props) {
const reset = linkEvent(this, this.resetState);
return ( return (
<form onSubmit={linkEvent(this, this.handleSubmit)}> <form onSubmit={linkEvent(this, this.handleSubmit)}>
<table class={scopedCss.editor + ' ' + scopedCss.exportsEditor}> <table class={scopedCss.editor + ' ' + scopedCss.exportsEditor}>
@ -463,8 +469,8 @@ export default function getProxyEditor(theState) {
this.state.stashedExports === false this.state.stashedExports === false
? 'Комментарии вырезаются!' ? 'Комментарии вырезаются!'
: (this.state.ifHasErrors : (this.state.ifHasErrors
? (<span><a href="" onClick={reset}>Сбросьте изменения</a> или поправьте</span>) ? (<span><a href="" onClick={this.resetState} style="color: red">Сбросьте изменения</a> или поправьте</span>)
: (<a href="" onClick={reset}>Сбросить изменения</a>) : (<a href="" onClick={this.resetState}>Сбросить изменения</a>)
) )
} }
</th> </th>