Created
March 27, 2018 19:47
-
-
Save Razzwan/19abc91a09e1b712e60c3fc5691a8a55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DateRangeField extends Component { | |
state = { | |
focusedInput: null, | |
} | |
handleCorrectInput = e => { | |
// some additional staff | |
switch (keyButton) { | |
case 42: | |
// some additional staff | |
return | |
default: | |
// some additional staff | |
this.handleValidationInput(e) | |
} | |
} | |
/** | |
* Что скажете по поводу этой функции валидации редакс формы? | |
*/ | |
handleValidationInput = e => { | |
const name = e.target.id.indexOf('start') !== -1 ? 'Start Date' : 'Finish Date' | |
const value = e.target.value | |
if (!/\d{2}\/\d{2}\/\d{4}/.test(value)) { | |
this.props.meta.touched = true | |
this.props.meta.error = { startDate: `${name}: Format must be MM/DD/YYYY` } | |
} else if (parseInt(value.substr(0, 2)) > 12) { | |
// some additional staff | |
} else { | |
this.props.meta.touched = false | |
} | |
} | |
render(){return null} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment