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

Plugin "Paint" doesn't work #2638

Open
3 tasks done
Oustinger opened this issue Aug 29, 2022 · 8 comments
Open
3 tasks done

Plugin "Paint" doesn't work #2638

Oustinger opened this issue Aug 29, 2022 · 8 comments

Comments

@Oustinger
Copy link

Oustinger commented Aug 29, 2022

Prerequisites

Describe the issue

Plugin "Paint" doesn't work if in options setted: { display: inline: true }. Example in the first StackBlitz fork
And if to add this option by "updateOptions()" after conneting "Paint" it doesn't work too (but in my project it fixes the bug...). Example in the second StackBlitz fork

StackBlitz fork

  1. first
  2. second

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Opera

What version of are you using? You can find this information from the sample StackBlitz.

6.0.0

What your browser's locale? You can find this information from the sample StackBlitz.

ru-RU

@Eonasdan Eonasdan added the State: Triage Tickets that need to be triaged. label Aug 29, 2022
@Alexandr120
Copy link

Alexandr120 commented Aug 29, 2022

I solved it like this
dates is object {2022-01-01 : "some style", 2022-01-02 : "some style"}
my function

const paintDate = (dates) => { picker.display.paint = (unit, date, classes) => { if (unit === tempusDominus.Unit.date) { var dateFormat = prepareDateFormat(date); if(dates.hasOwnProperty(dateFormat)){ classes.push(dates[dateFormat]); } } } }
prepareDateFormat() method returned format "yyyy-mm-dd".
For style i created some class map.

But I have one problem. Dates are only drawn if I select a date. I would like this to happen immediately when the calendar is initialized

@Alexandr120
Copy link

result in page
image

@Oustinger
Copy link
Author

Oustinger commented Sep 2, 2022

@Alexandr120 Can you create an example like that, please? I'm hardly understand your solution..

@Oustinger
Copy link
Author

I've fixed my problem with a some sort of crutch. Example

@Alexandr120
Copy link

@Oustinger done!. Lock here

if i creted exemple not correctly, you can try use this
`import * as tempusDominus from '@eonasdan/tempus-dominus';

//example picker
const datetimepicker1 = new tempusDominus.TempusDominus(
document.getElementById('datetimepicker1'),
{
display: {
inline: true,
},
}
);

const specilDates = {
'2022-09-10' : 'green',
'2022-09-11' : 'yellow',
'2022-09-12' : 'red'};

const getDateFormat = (dateTime) => {
let currentDate = new Date(dateTime);
let year = currentDate.getFullYear();
let month = currentDate.getMonth() + 1;
month = (month < 10)? 0${month} : month;
let date = currentDate.getDate();
date = (date < 10)? 0${date} : date;
return ${year}-${month}-${date}
}

datetimepicker1.display.paint = (unit, date, classes, element) => {
let dateFormat = getDateFormat(date);
if(specilDates.hasOwnProperty(dateFormat)){
classes.push(specilDates[dateFormat]);
}
};`

@Alexandr120
Copy link

here result of my example
image

@Oustinger
Copy link
Author

@Alexandr120 Thanks. But painting of days starts only after selecting any date. I need to do it with the first render of calendar...

@Eonasdan Eonasdan added Area: TypeScript Priority: Low Area: Plugins and removed State: Triage Tickets that need to be triaged. labels Oct 24, 2022
@Eonasdan
Copy link
Owner

Hi everyone.

The issue here is that the paint function is getting set after the rendering has already happened. This is only an issue with the inline view. You currently have two options.

  1. use datetimepicker.display._rebuild().
  2. if you only have one picker (or want to affect them all), you can set a global paint function with the extend
const painter = (option, tdClasses, tdFactory) => {
    // noinspection JSUnusedLocalSymbols
    tdClasses.Display.prototype.paint = (
      unit,
      date,
      classes,
      element
    ) => {
      debugger;
      if (unit === tdFactory.Unit.date) {
        if (date.isSame(new tdFactory.DateTime(), unit)) {
          classes.push('special-day');
        }
      }
    };
  }

tempusDominus.extend(painter);

Unfortunately, there's not a good way to get which picker is calling the global extends.

@Anzil-Aufait your issue comes from the fact the paint happens before the innerText is set on the element. That means that attempt to use appendChild be get overwritten.

I know this is not ideal for your situations, but I'm not sure what I can do without making a breaking change.

If you have ideas or would like to submit a PR, I'm open to that.

Perhaps in v7 there will be a better way to deal with it.

@Eonasdan Eonasdan added this to the 7.0 milestone Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants