Closed reza-agahi closed 5 years ago
hi i'll check it out ASAP.
@reza-agahi can i see your code?
seems like its the same problem that mentioned on issue #4 .
use moment.loadPersian();
and see if it resolve.
It's still not working :( and throwing error some times
@pouyajabbarisani u know, i need to see your code ...
Seems DakePicker generates invalid date, cuz It's throw error for a saved date which selected and generated by itself. (code exactly as same as I explained in https://github.com/mberneti/react-datepicker2/issues/20#issuecomment-497963708)
Oh, It was all about my wrong date formatting. I'm gonna debug my code in https://github.com/mberneti/react-datepicker2/issues/20#issuecomment-497963708
@pouyajabbarisani It's not invalid, it's different and based on momentJs date. That's your fault u should not manipulate the selected value.
So can I close this issue?
Sure, thanks for everything :)
You're welcome ;)
Hi My problem is the same as the problem explained in this topic (https://github.com/mberneti/react-datepicker2/issues/15#issue-354008227). and here is my code:
import React from "react";
import moment from "moment-jalaali";
import DatePicker from "react-datepicker2";
// moment.loadPersian({ dialect: "persian-modern" });
export default class ReactClass extends React.Component {
constructor(props) {
super(props);
this.state = { value: moment() };
}
render() {
return (
<DatePicker
timePicker={false}
isGregorian={false}
onChange={value => {
this.setState({ value });
}}
value={this.state.value}
/>
);
}
}
please help me to solve this error.
P.S. : adding or removing the comment line did not solve my problem.
@EslahiSani I'll check it ASAP.
@moesaniii you don't need to call loadPersian method of the moment any more, there isn't any problem in the current version. can u show me the code?
@mberneti , loadPersian is commented and I have used the exact code explained in https://github.com/mberneti/react-datepicker2/issues/15#issuecomment-513662934
@moesaniii I can't see any error in this conditions:
"dependencies": {
"moment-jalaali": "^0.8.3"
...
},
"peerDependencies": {
"react": "^16.0.0"
...
}
@mberneti conditions of our project:
"moment-jalaali": "^0.8.3"
"react": "^16.8.1"
@moesaniii unfortunately i cannot see any problem, so i can't resolve it.
I have got same issue here and this is my code:
import React, { useMemo } from 'react';
import { useTranslate, useInput } from 'react-admin';
import DatePicker from './dp/index';
import moment from 'moment-jalaali';
import { withStyles } from '@material-ui/core';
import FormHelperText from '@material-ui/core/FormHelperText';
import lodashGet from 'lodash/get';
import './JalaliDateInput.css';
import { SERVER_DATE_FORMAT } from '../container/DateInputContainer';
import { getValue, CONFIG_CALENDAR } from '../core/configProvider';
const JalaliDateInput = props => {
const {
classes,
label,
DateInputInPuzzleForm,
source,
disabled,
visibleClass,
inputFormat,
} = props;
const translate = useTranslate();
const calendarConfig = getValue(CONFIG_CALENDAR);
const {
input: { name, onChange, value },
meta: { touched, error },
isRequired,
} = useInput(props);
const internalValue = useMemo(() => {
if (!value) {
return null;
}
return moment(value, SERVER_DATE_FORMAT);
}, [value]);
const handleChange = changedDate => {
const newValue = changedDate ? changedDate.locale('en').format(SERVER_DATE_FORMAT) : null;
if (newValue === value) {
return;
}
props.onChange(newValue);
onChange(newValue);
};
return (
<fieldset
id={`date-picker-${source}`}
className={`${visibleClass} datePickerContainer`}
data-error={touched && !!error}
data-label={!!label || label !== ''}
data-puzzle-form={!!DateInputInPuzzleForm}
disabled={disabled}
>
{label && label !== '' && <legend className={classes.legend}>{label}</legend>}
<DatePicker
inputFormat={inputFormat}
onChange={handleChange}
value={internalValue}
disabled={disabled}
isGregorian={calendarConfig === 'gregorian'}
timePicker={false}
showTodayButton={false}
/>
{touched && !!error && (
<FormHelperText error className={classes.error}>
{translate(lodashGet(error, 'message', error))}
</FormHelperText>
)}
</fieldset>
);
};
JalaliDateInput.defaultProps = {
onBlur: () => {},
onChange: () => {},
inputFormat: 'jYYYY-jMM-jDD',
};
export default withStyles(styles, { withTheme: true })(JalaliDateInput);
Hello @mberneti ?
Hi Dear Mohammadreza! error scenario: I go to provided section for selecting month,
and when I click on each of these months, I get this error and datepicker doesn't update:
This problem just occured when I set isGregorian={false} and for gregorian calendar it is fine!
conditions: