Discuss anything related to web development but no technical support questions


Post by lxxrxns »

Excuse me for posting this in this sub forum, I'm still on a trial version testing things out to see if Bryntum Calendar can work for me and I can't post in the Calendar forums anymore. Maybe someone can move this topic to the Calendar sub forum? Thanks.

I would like to know if I can set a default start time and end time for an event that is created by double clicking in the Month view or Agenda view. By default, the start time is 08:00 and the end time 09:00, but I would -for example- like to set it to 13:00:

Image

Can this be done with the onEventCreated function?
Calendar doesn't seem to have a listener for beforeEventEditShow like Scheduler does (according to the docs at least), and also I would only want this for NEW events (not when editing another event that already has a set starttime/endtime).

Any help would be greatly appreciated!


Post by Animal »

Each mode (child view) of a Calendar has this config option: https://www.bryntum.com/docs/calendar/api/Calendar/widget/mixin/CalendarMixin#config-autoCreate

To set common configurations for all modes in a Calendar, use this property on the Calendar: https://www.bryntum.com/docs/calendar/api/Calendar/view/Calendar#config-modeDefaults


Post by Animal »

So configure your Calendar with this:

    modeDefaults : {
        autoCreate : {
            startHour : 13
        }
    }

Post by lxxrxns »

Thanks for the quick response!

I have:

modes : {
  month: { 
    autoCreate : {
      startHour: 9,
      duration: '1 hour'
    }
  }
}

But this doesn't seem to work.
What am I doing wrong?

And can I also set the start time to half hours, i.e 9.30? Would I have to do 9.5 for that?


Post by lxxrxns »

I also tried

modeDefaults : {
        autoCreate : {
            startHour : 13
        }
    }

I put this in the main calendar code, i.e. after the features {} segment.

Is that OK?


Post by lxxrxns »

Update:

I did it without the modeDefaults part, so I just put autoCreate in the main config part (next to features, sidebar, listeners, etc) and now it works!

Thanks for the help anyways!


Post by lxxrxns »

The only thing that doesn't work yet is the half hour part:

autoCreate : {
      startHour : '13.5'
    },

With or without quotes, a new event is created at 13:00, not 13:30, even though the docs say:

This is the hour of the day to start the event at. It may be fractional.


Post by Animal »

Yes, I forgot, we import the autoCreate setting from the calendar into the views by default.

Non fractional startHour is a bug. The code tries to set it, but the underlying date utility doesn't accept fractional hours

It asks for

DateHelper.set(dateStart, 'hour', autoCreate.startHour);

But DateHelper doesn't cooperate. I will have to make it convert the hour to second and use

DateHelper.set(dateStart, 'second', autoCreate.startHour * 60 * 60);

Here is the ticket for this issue: https://github.com/bryntum/support/issues/4597


Post by lxxrxns »

Thanks again for the response!

For a work-around, is there any way to programmatically set the starting time (hours and minutes) of an event under certain conditions?

E.g. if I change my resource combo menu value, can I automatically change the value of the starting time depending on the resourceId that's selected?

Something like (I don't know the exact correct syntax yet):

listeners:{
 change(record){ 
  // something like:
  if (record.resourceId==1){
    record.startTime= Date(something to set the time to 13:30...);
  }
 }
}

In Scheduler I managed to get something similar working, but in Calendar I couldn't get it to work...


Post by Animal »

You can listen for this event, and mutate the eventRecord as you see fit: https://www.bryntum.com/docs/calendar/api/Calendar/view/Calendar#event-eventAutoCreated

Remember that if you dblclick in a DayView or WeekView, start time is included in the gesture (The user will click on the time required, and the autoCreate.step will snap it to a boundary), so probably do not intervene if activeView.isDayView (A WeekView is a DayView, but with 7 days)


Post Reply