Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date time picker doesn't work #305

Open
joaoamorim99 opened this issue Nov 2, 2022 · 1 comment
Open

Date time picker doesn't work #305

joaoamorim99 opened this issue Nov 2, 2022 · 1 comment

Comments

@joaoamorim99
Copy link

I put type="datetime" on html and it doesn't work.

@lukajose
Copy link

try the following, if you are using react :

import bulmaCalendar from 'bulma-calendar';
import 'bulma-calendar/dist/css/bulma-calendar.min.css';
import { useEffect } from 'react';

const Calendar = ({className,onSelect, defaultDate = new Date()}) => {
  
  useEffect(() => {
    // Initialize all input of date type.
    const calendars = bulmaCalendar.attach('[type="datetime"]', {
      isRange: true,
    });

    // Loop on each calendar initialized
    calendars.forEach((calendar) => // Add listener to date:selected event
      calendar.on('select', (date) => {
        console.log("selected a date:", date)
        
      }));

    // To access to bulmaCalendar instance of an element
    // eslint-disable-next-line no-undef
    const element = document.querySelector('#calendar');
    if (element) {
      // bulmaCalendar instance is available as element.bulmaCalendar
      element.bulmaCalendar.on('select', (datepicker) => {
        console.log(datepicker.data.value());
        console.log(typeof datepicker.data.value());
        const dateTime = Date(datepicker.data.value());
        console.log("my datetime:",datetime);
        onSelect(dateTime);
      });
    }
    
  }, []);

  return (
    <div className={className}>
      <input id="calendar" type="datetime" data-color="dark" />
    </div>
  );
};

export default Calendar;


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants