Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
olegstan committed Jul 2, 2024
1 parent 364aead commit 906fa07
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 71 deletions.
42 changes: 23 additions & 19 deletions dist/Form/Date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
};
Expand Down Expand Up @@ -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: () => {
Expand Down
32 changes: 18 additions & 14 deletions dist/Form/DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "finform",
"version": "1.4.6",
"version": "1.4.7",
"description": "",
"main": "dist/index.js",
"repository": {
Expand Down
42 changes: 21 additions & 21 deletions src/Form/Date.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
};
Expand Down Expand Up @@ -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={() => {
Expand Down
35 changes: 19 additions & 16 deletions src/Form/DateTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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={() => {
Expand Down

0 comments on commit 906fa07

Please sign in to comment.