From 906fa07c4d99f13266760e03709a850d93160c69 Mon Sep 17 00:00:00 2001 From: olegstan Date: Tue, 2 Jul 2024 11:30:22 +0300 Subject: [PATCH] fixes --- dist/Form/Date.js | 42 +++++++++++++++++++++++------------------- dist/Form/DateTime.js | 32 ++++++++++++++++++-------------- package.json | 2 +- src/Form/Date.jsx | 42 +++++++++++++++++++++--------------------- src/Form/DateTime.jsx | 35 +++++++++++++++++++---------------- 5 files changed, 82 insertions(+), 71 deletions(-) diff --git a/dist/Form/Date.js b/dist/Form/Date.js index a01de06..50cb2f4 100644 --- a/dist/Form/Date.js +++ b/dist/Form/Date.js @@ -78,14 +78,31 @@ export default class DateTime extends BaseInput { if (day.length < 2) day = '0' + day; return [day, month, year].join('.'); } - handleDateChange = date => { + handleDateChange = value => { + const date = new Date(value); + const formattedDate = this.formatDate(date); this.setState({ - date: date[0] + date: formattedDate }); - if (this.props.onChangeDateInner) { + this.props.onChangeDateInner({}, { + date: formattedDate, + value: formattedDate + }); + }; + handleInputChange = e => { + const value = e.target.value; + this.setState({ + date: value + }); + if (typeof value === 'string' && value !== '__.__.____' && !value.includes('_')) { + this.props.onChangeDateInner({}, { + date: value, + value: value + }); + } else { this.props.onChangeDateInner({}, { - value: this.formatDate(date[0]), - date: date[0] + date: null, + value: value }); } }; @@ -149,20 +166,7 @@ export default class DateTime extends BaseInput { mask: "99.99.9999", id: id, value: props.value, - onChange: e => { - let value = e.target.value; - if (typeof value === 'string' && value !== '__.__.____' && !value.includes('_')) { - this.props.onChangeDateInner({}, { - date: value, - value: value - }); - } else { - this.props.onChangeDateInner({}, { - date: null, - value: value - }); - } - }, + onChange: this.handleInputChange, style: props.style, className: props.className, onFocus: () => { diff --git a/dist/Form/DateTime.js b/dist/Form/DateTime.js index c6ef1d9..b8c82bc 100644 --- a/dist/Form/DateTime.js +++ b/dist/Form/DateTime.js @@ -40,6 +40,23 @@ export default class DateTime extends Date { const second = date.getSeconds().toString().padStart(2, '0'); return `${day}.${month}.${year} ${hour}:${minute}:${second}`; } + handleInputChange = e => { + const value = e.target.value; + this.setState({ + date: value + }); + if (typeof value === 'string' && value !== '__.__.____ __:__:__' && !value.includes('_')) { + this.props.onChangeDateInner({}, { + date: value, + value: value + }); + } else { + this.props.onChangeDateInner({}, { + date: null, + value: value + }); + } + }; render() { const { Input, @@ -97,20 +114,7 @@ export default class DateTime extends Date { mask: "99.99.9999 99:99:99", id: id, value: props.value, - onChange: e => { - let value = e.target.value; - if (typeof value === 'string' && value !== '__.__.____ __:__:__' && !value.includes('_')) { - this.props.onChangeDateInner({}, { - date: value, - value: value - }); - } else { - this.props.onChangeDateInner({}, { - date: null, - value: value - }); - } - }, + onChange: this.handleInputChange, style: props.style, className: props.className, onFocus: () => { diff --git a/package.json b/package.json index 5d1f17f..5a322b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "finform", - "version": "1.4.6", + "version": "1.4.7", "description": "", "main": "dist/index.js", "repository": { diff --git a/src/Form/Date.jsx b/src/Form/Date.jsx index 78b2c0f..3042678 100644 --- a/src/Form/Date.jsx +++ b/src/Form/Date.jsx @@ -92,12 +92,27 @@ export default class DateTime extends BaseInput { return [day, month, year].join('.'); } - handleDateChange = (date) => { - this.setState({ date: date[0] }); - if (this.props.onChangeDateInner) { + handleDateChange = (value) => { + const date = new Date(value); + const formattedDate = this.formatDate(date); + this.setState({ date: formattedDate }); + this.props.onChangeDateInner({}, { date: formattedDate, value: formattedDate }); + }; + + handleInputChange = (e) => { + const value = e.target.value; + + this.setState({ date: value }); + + if (typeof value === 'string' && value !== '__.__.____' && !value.includes('_')) { this.props.onChangeDateInner({}, { - value: this.formatDate(date[0]), - date: date[0] + date: value, + value: value, + }); + } else { + this.props.onChangeDateInner({}, { + date: null, + value: value, }); } }; @@ -164,22 +179,7 @@ export default class DateTime extends BaseInput { mask="99.99.9999" id={id} value={props.value} - onChange={(e) => { - let value = e.target.value; - - if(typeof value === 'string' && value !== '__.__.____' && !value.includes('_')) - { - this.props.onChangeDateInner({}, { - date: value, - value: value - }); - }else{ - this.props.onChangeDateInner({}, { - date: null, - value: value - }); - } - }} + onChange={this.handleInputChange} style={props.style} className={props.className} onFocus={() => { diff --git a/src/Form/DateTime.jsx b/src/Form/DateTime.jsx index b71b1bb..d2a9a09 100644 --- a/src/Form/DateTime.jsx +++ b/src/Form/DateTime.jsx @@ -49,6 +49,24 @@ export default class DateTime extends Date return `${day}.${month}.${year} ${hour}:${minute}:${second}`; } + handleInputChange = (e) => { + const value = e.target.value; + + this.setState({ date: value }); + + if (typeof value === 'string' && value !== '__.__.____ __:__:__' && !value.includes('_')) { + this.props.onChangeDateInner({}, { + date: value, + value: value, + }); + } else { + this.props.onChangeDateInner({}, { + date: null, + value: value, + }); + } + }; + render() { const {Input, componentsLoaded} = this.state; @@ -102,22 +120,7 @@ export default class DateTime extends Date mask="99.99.9999 99:99:99" id={id} value={props.value} - onChange={(e) => { - let value = e.target.value; - - if(typeof value === 'string' && value !== '__.__.____ __:__:__' && !value.includes('_')) - { - this.props.onChangeDateInner({}, { - date: value, - value: value - }); - }else{ - this.props.onChangeDateInner({}, { - date: null, - value: value - }); - } - }} + onChange={this.handleInputChange} style={props.style} className={props.className} onFocus={() => {