From e28d054d4894557d12202096bb6d65b421af4628 Mon Sep 17 00:00:00 2001 From: Gabriel de Souza Climaco Date: Sun, 21 Oct 2018 17:15:02 -0300 Subject: [PATCH] =?UTF-8?q?Jun=C3=A7=C3=A3o=20das=20fun=C3=A7=C3=A3o=20'se?= =?UTF-8?q?tYear'=20e=20'setMonth'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/containers/DateOfBirthForm/SelectDate.js | 32 +++++++++----------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/containers/DateOfBirthForm/SelectDate.js b/src/containers/DateOfBirthForm/SelectDate.js index 9d7d1b2..a617c52 100644 --- a/src/containers/DateOfBirthForm/SelectDate.js +++ b/src/containers/DateOfBirthForm/SelectDate.js @@ -20,25 +20,14 @@ export class SelectDate extends React.Component { preeschoolCalcError: null, ageMsg: null }; - this.setMonth = this.setMonth.bind(this) - this.setYear = this.setYear.bind(this) + this.setDateAttribute = this.setDateAttribute.bind(this); } - setMonth = (e) => { + setDateAttribute = (attribute, value) => { this.setState({ - monthOfBirth: e.target.value + [attribute]: value }, () => { - if (this.state.yearOfBirth !== undefined) { - this.setAge(); - } - }); - } - - setYear = (e) => { - this.setState({ - yearOfBirth: e.target.value - }, () => { - if (this.state.monthOfBirth !== undefined) { + if (this.state.yearOfBirth !== undefined && this.state.monthOfBirth !== undefined) { this.setAge(); } }); @@ -67,11 +56,20 @@ export class SelectDate extends React.Component { const preeschoolCalcError = this.state.preeschoolCalcError; return (
- this.setDateAttribute('monthOfBirth', event.target.value)} + > {generateMonthsOptions()} - this.setDateAttribute('yearOfBirth', event.target.value)} + > {generateYearsOptions()}