Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI Pickers - Jalali Calendar Issue

I am using Material-UI pickers in my react app and I am having difficulty getting the Jalali calendar example to work. The version of the packages that I am using is:

"@date-io/jalaali": "^1.3.13",
"@date-io/moment": "^1.3.13",
"@material-ui/core": "^4.8.3",
"@material-ui/icons": "^4.5.1",
"@material-ui/pickers": "^3.2.8",
"moment": "^2.24.0",
"moment-jalaali": "^0.9.1",
"react": "^16.12.0",
"react-scripts": "3.3.0",
"react-dom": "^16.12.0",

The Error is TypeError: utils.getDayText is not a function for DatePicker, TypeError: utils.getHourText is not a function for TimePicker, and TypeError: utils.getYearText is not a function for DateTimePicker. I tried to change the version of some packages but nothing happen.

Edit:

I found that the problem is the JalaliUtils in the <MuiPickersUtilsProvider utils={JalaliUtils} locale="fa">, but still can't find the solution.

import moment from "moment";
import jMoment from "moment-jalaali";
import React, { useState } from "react";
import JalaliUtils from "@date-io/jalaali";

import {
  DatePicker,
  MuiPickersUtilsProvider,
} from "@material-ui/pickers";

jMoment.loadPersian({ dialect: "persian-modern", usePersianDigits: true });

function PersianExample() {
  const [selectedDate, handleDateChange] = useState(moment());

  return (
    <MuiPickersUtilsProvider utils={JalaliUtils} locale="fa">
      <DatePicker
        clearable
        okLabel="تأیید"
        cancelLabel="لغو"
        clearLabel="پاک کردن"
        labelFunc={date => (date ? date.format("jYYYY/jMM/jDD") : "")}
        value={selectedDate}
        onChange={handleDateChange}
      />
    </MuiPickersUtilsProvider>
  );
}

export default PersianExample;
like image 257
F-Fardin Avatar asked Jan 16 '20 07:01

F-Fardin


People also ask

How do I install Jalaali or Hijri on material-UI?

Make sure that you have read the right to left section of the material-ui documentation page before proceeding. Install the specified npm packages below for Jalaali or Hijri depending on which calendar system you will be using. Install @date-io/jalaali package from npm. You can use the examples below. It is recommended that you change the font.

What happened to material-UI V4 pickers?

After the long year or of work on v4 pickers are finally taking a place at material-ui. This project is no longer supported and the documentation as well. We are going to close the docs and put all the work on material-ui v5 stable release which will include the new era of date & time picking!

What are the different types of date pickers?

Date pickers 1 Anatomy 2 Mobile pickers. Mobile calendar pickers can be used to select dates in the near future or past, when it’s useful to see them in a calendar month ... 3 Desktop pickers. Desktop date pickers allow the selection of a specific date and year. The desktop date picker displays a date input field by default, and a ...

What is a mobile date input picker?

Mobile date input pickers allow the manual entry of dates using the numbers on a keyboard. Users can input a date or a range of dates in a dialog. Mobile date input picker Mobile date input pickers allow for keyboard input to select a date or range of dates.


1 Answers

Strangely the example now is working with the "@date-io/jalaali": "^1.3.12" however, there is not a serious difference between these two versions. Thank you Alex for your sandbox.

like image 78
F-Fardin Avatar answered Oct 13 '22 02:10

F-Fardin