Skip to main content
  1. About
  2. For Teams
Asked
Viewed 5k times
1

I'm using a Tailwind CSS Datepicker from Flowbite. Everything works fine, but I cannot find the option to change starting day of week to Monday instead of default Sunday.

<div date-rangepicker  class="flex items-center">
 <div class="relative">
  <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none">
        <svg class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd"></path></svg>
       </div>
     <input name="start" type="text" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5  dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Select date start" required>
  </div>
  <span class="mx-4 text-gray-500">to</span>
  <div class="relative">
       <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none">
         <svg class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd"></path></svg>
       </div>
    <input name="end" type="text" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5  dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Select date end" required>
  </div>
</div>

You can see my code upwards. For default is Sunday as a 1st day of week:

enter image description here

Is it possible to change it? And if it is, how?

5
  • does anyone got similar problem?
    kalview
    –  kalview
    2022-04-12 10:01:46 +00:00
    Commented Apr 12, 2022 at 10:01
  • I just brute force it by modified the code inside the node_modules.
    Mario Ariyanto
    –  Mario Ariyanto
    2022-08-31 23:54:36 +00:00
    Commented Aug 31, 2022 at 23:54
  • Can you explain it a little bit more?
    kalview
    –  kalview
    2022-09-01 09:50:31 +00:00
    Commented Sep 1, 2022 at 9:50
  • 1
    I have created the answer post. Hope it helps
    Mario Ariyanto
    –  Mario Ariyanto
    2022-09-02 01:38:53 +00:00
    Commented Sep 2, 2022 at 1:38
  • You should be able to pass in weekStart value in options when instantiating a new datepicker. Check this out - stackoverflow.com/questions/73566007/…
    mojorisinify
    –  mojorisinify
    2022-09-10 23:51:23 +00:00
    Commented Sep 10, 2022 at 23:51

4 Answers 4

3

Following up on Mario's answer.

Flowbite datepicker does allow you to change the locale. Check this answer on how to do it.

You should be able to change start of the week by passing in weekStart while initializing Datepicker like below -

let element = document.getElementById(elementId); //id of the input element
var options = {weekStart: 1}
var datepicker = new Datepicker(element, options)

Alternatively, you should also be able to pass in the actual locale as such -

Datepicker.locales.es = {
    days: ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"],
    daysShort: ["Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"],
    daysMin: ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa"],
    months: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
    monthsShort: ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
    today: "Hoy",
    monthsTitle: "Meses",
    clear: "Borrar",
    weekStart: 1,
    format: "dd/mm/yyyy"
  }

It will pick up all the localized values from the locales object.

Sign up to request clarification or add additional context in comments.

Comments

0

This datepicker also has the option to set the first day of week to Sunday (by passing locale.sundayFirst: true as a prop):

https://github.com/mohsentaleb/react-tailwindcss-datetimepicker

You may take a look at it.

Comments

0

In Laravel with tailwindcss, flowbite and flowbite-datepicker installed via npm you do the following in app.js

import Datepicker from 'flowbite-datepicker/Datepicker';
const datepickerEl = document.getElementById('elementId'); // replace elementId
new Datepicker(datepickerEl, {
    weekStart: 1
}

Comments

-2

Because Flowbite doesn't provide the command to change things such as starting day of the week, and locale. You need to change the javascript code straight from the library, that is inside the node_modules.

This is the folder directory in Laravel.

enter image description here

Find the Flowbite library->dist->datepicker.js

enter image description here

Find defaultOptions variable, and modified the weekStart to 1.

enter image description here

enter image description here

The result:

enter image description here

N.B: You can also define a new locale using this method.
You need to download the library into the project for this to work.

3 Comments

The edits you make in the node_modules will go away when doing a fresh npm install. This is a hacky way of making this work. You should be able to pass in options while calling Datepicker constructor. I made a comment above.
Yes, that's why I said it is a brute force method. Works but not the best way to do
Do not use this approach. It will lead to dodgy stuff like committing node_modules or forking the repo. Change the settings as per mojorisinify's answer.

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.