react-multi-date-picker icon indicating copy to clipboard operation
react-multi-date-picker copied to clipboard

get english characters instead of persian

Open AliAmiresmaeili opened this issue 3 years ago • 3 comments

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 ?

AliAmiresmaeili avatar Sep 10 '22 06:09 AliAmiresmaeili

Hi. Please follow this sandbox:

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

shahabyazdi avatar Sep 10 '22 06:09 shahabyazdi

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

AliAmiresmaeili avatar Sep 11 '22 10:09 AliAmiresmaeili

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} />

...

mohammadoftadeh avatar Sep 24 '23 12:09 mohammadoftadeh