Petit nettoyage de Input.js

Gestion des erreurs et de la validation
pull/138/head
mama 2017-12-18 15:15:05 +01:00
parent b6707a256b
commit 1b8e212526
3 changed files with 14 additions and 15 deletions

View File

@ -85,9 +85,11 @@ export var FormDecorator = formType => RenderField =>
/* There won't be any answer zone here, widen the question zone */
let wideQuestion = formType == 'rhetorical-question' && !possibleChoice
let { pre = v => v, test, error } = valueType ? valueType.validator : {},
validate = test && (v => (v && test(pre(v)) ? undefined : error))
let question = (
<h1
style={{

View File

@ -14,15 +14,15 @@ export default class Input extends Component {
let {
input,
stepProps: { dottedName, attributes, submit, valueType },
meta: { touched, error, active },
meta: { dirty, error, active },
themeColours
} = this.props,
answerSuffix = valueType.suffix,
suffixed = answerSuffix != null,
inputError = touched && error,
inputError = dirty && error,
{ hoverSuggestion } = this.state,
sendButtonDisabled =
input.value == null || input.value == '' || inputError
submitDisabled =
!dirty || inputError
return (
<span>
@ -43,11 +43,8 @@ export default class Input extends Component {
}
onKeyDown={
({ key }) =>
key == 'Enter' &&
input.value &&
(!error ? submit() : input.onBlur())
// blur will trigger the error
key == 'Enter'
&& (submitDisabled ? input.onBlur() : submit())
}
/>
{suffixed && (
@ -60,7 +57,7 @@ export default class Input extends Component {
</label>
)}
<SendButton
{...{ sendButtonDisabled, themeColours, error, submit }}
{...{disabled: submitDisabled, themeColours, error, submit }}
/>
</div>

View File

@ -4,16 +4,16 @@ import HoverDecorator from 'Components/HoverDecorator'
@HoverDecorator
export default class SendButton extends Component {
getAction(){
let {sendButtonDisabled, error, submit } = this.props
return () => (!sendButtonDisabled && !error ? submit() : null)
let {disabled, submit } = this.props
return () => (!disabled ? submit() : null)
}
render() {
let { sendButtonDisabled, themeColours, hover } = this.props
let { disabled, themeColours, hover } = this.props
return (
<span className="sendWrapper">
<button
className="send"
disabled={sendButtonDisabled}
disabled={disabled}
style={{
color: themeColours.textColour,
background: themeColours.colour
@ -25,7 +25,7 @@ export default class SendButton extends Component {
</button>
<span
className="keyIcon"
style={{ opacity: hover && !sendButtonDisabled ? 1 : 0 }}
style={{ opacity: hover && !disabled ? 1 : 0 }}
>
Entrée{' '}
</span>