Skip to content

Instantly share code, notes, and snippets.

@Razzwan
Created March 27, 2018 19:47
Show Gist options
  • Save Razzwan/19abc91a09e1b712e60c3fc5691a8a55 to your computer and use it in GitHub Desktop.
Save Razzwan/19abc91a09e1b712e60c3fc5691a8a55 to your computer and use it in GitHub Desktop.
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