This JavaScript code provides a Persian Datepicker, allowing users to select dates in a Persian (jalali) calendar format. The core functionality enables date selection for various input fields. It’s helpful for displaying and capturing Persian dates easily.
Moreover, you can integrate this Persian Datepicker code into web applications, and cultural/educational platforms to offer users a convenient way to select Persian dates and schedule appointments. Similarly, you can integrate this datepicker in online booking system.
How to Create Persian Datepicker In JavaScript
1. In your HTML file, include the necessary dependencies for the Persian Datepicker. Add the following CDN links to the <head>
section of your HTML file:
<link rel='stylesheet' href='https://unpkg.com/@majidh1/jalalidatepicker/dist/jalalidatepicker.min.css'> <script src='https://unpkg.com/@majidh1/jalalidatepicker/dist/jalalidatepicker.min.js'></script>
2. Create the date input fields with type "text"
in your HTML where you want the Persian Datepicker to appear. You can customize the input fields as needed.
<h1 style="text-align:center">jalali datePicker - دیت پیکر شمسی</h1> <input type="text" data-jdp placeholder="لطفا یک تاریخ وارد نمایید" /> <input type="text" data-jdp data-jdp-min-date="today" placeholder="نمایش تاریخ از امروز" /> <input type="text" data-jdp data-jdp-max-date="today" placeholder="نمایش تاریخ تا امروز" /> <input type="text" data-jdp data-jdp-max-date="1401/10/08" placeholder="نمایش تاریخ تا 1401/10/08" /> <div class="settings" dir="rtl"> <a target="_blank" href="https://github.com/majidh1/JalaliDatePicker"> Github </a> </div> <p>این پلاگین تنظیمات زیادی دارد که می توانید از لینک github مستندات کاملش رو مشاهده کنید.</p> <p> با انتخاب کنترل input پلاگین date picker فعال شده و می توانید تاریخ مورد نظر خود را انتخاب نمایید</p> <h1>persian date picker</h1>
3. You can customize the styling of the datepicker by modifying the following CSS code or by adding your own styles. (Optional)
@font-face { font-family: "Samim"; src: url('Samim/Samim-FD.woff2') format('woff2'), url('Samim/Samim-FD.woff') format('woff'), url('Samim/Samim-FD.ttf') format('truetype'); } * { font-family: "Samim"; } body { font-size: 14px; background-color: #fcfcfc; } input { border: 2px solid #ccc; border-radius: 5px; height: 38px; line-height: 38px; width: 309px; font-size: 16px; padding: 0 5px; color: #666; display: block; margin-top:20px; margin-bottom:40px; margin-right: auto; margin-left:auto; } ::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */ text-align: center; } :-ms-input-placeholder { /* Internet Explorer 10-11 */ text-align: center; } ::-ms-input-placeholder { /* Microsoft Edge */ text-align: center; } .settings{ position: fixed; z-index: 1; bottom:5px; right: 5px; width:150px; padding:5px; text-align: center; background-color: rgb(242, 255, 124) } .settings *{ vertical-align: middle; text-decoration: none; font-weight: 900; letter-spacing: 1px; } img{ max-width: 100%; } p { text-align: center; direction: rtl; } .divider{ height: 20vh; }
4. In your JavaScript code, initialize the Persian Datepicker by calling the jalaliDatepicker.startWatch
function. You can set options like minDate
and maxDate
if needed.
jalaliDatepicker.startWatch({ minDate: "attr", maxDate: "attr" }); /* Below is a js demo | you don't need to use */ setTimeout(function(){ var elm=document.getElementsByTagName("input")[0]; elm.focus(); jalaliDatepicker.hide(); jalaliDatepicker.show(elm); }, 1000);
That’s all! Hopefully, you’ve successfully integrated the Persian Datepicker into your web project, allowing users to select Persian dates effortlessly. If you have any questions or suggestions, feel free to comment below.
Similar Code Snippets:
I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.