shahabyazdi / react-multi-date-picker

a simple React datepicker component for working with gregorian, persian, arabic and indian calendars
https://shahabyazdi.github.io/react-multi-date-picker/
MIT License
831 stars 102 forks source link

get english characters instead of persian #131

Open AliAmiresmaeili opened 2 years ago

AliAmiresmaeili commented 2 years ago

i am using persian calendar with locale={persian_fa} and using react-hook-form , when i get values from data object of react-hook-form , it have persian numbers for data picker , i got problems when post these data to server , i can convert this string programmatically , but is there a way to get english characters from datepicker ?

shahabyazdi commented 2 years ago

Hi. Please follow this sandbox:

https://codesandbox.io/s/ecstatic-scott-iuzuqr?file=/src/App.js

AliAmiresmaeili commented 2 years ago

i used react hook form controller and i did not ued onchange to set value because of controller, this link you sent did not help me , now i dont know what to do

mohammadoftadeh commented 1 year ago

This method may be useful:

...

  const [value, setValue] = useState<DateObject | string>("");

  function handleChange(dValue: DateObject) {
    // console.log(dValue?.toDate?.());
    const {
      year,
      month: { number },
      day,
    } = dValue;

    setValue(`${year}/${number.toString().padStart(2, "0")}/${day}`); // output for exp: `1402/07/02` instead of `۱۴۰۲/۰۷/۰۲`
  }

  // For special cases
  <input type="hidden" name="date_en" value={value} />
  <DatePicker calendar={persian} locale={persian_fa} value={value} onChange={handleChange} />

...