Our pure JavaScript Scheduler component


Post by clemenshimmer »

https://bryntum.com/products/scheduler/docs/api/Core/widget/Widget exposes no interface to set it's value programatically.

The following code are two widget configs that control the display range of the scheduler, the second one jumps to today, and also sets the datefield widget's value so it may be controlled properly corresponding to where the range was set (today).
This code works, albeit it disagrees with the types provided, as they do not expose the value property.


    {
      type: 'datefield',
      format: 'dd DD.MM.YYYY',
      id: 'date',
      value: this.scheduler.startDate,
      step: this.scheduler_step,
      onChange: ({ value }) => {
        if (this.scheduler_step === '1d') {
          this.setDisplayRangeOfScheduler(value, 'day');
        } else if (this.scheduler_step === '1w') {
          this.setDisplayRangeOfScheduler(value, 'week');
        }
      }
    },
    {
      type: 'button',
      text: 'Heute',
      tooltip: 'Springe auf heute',
      onAction: () => {
        const now = new Date();
        this.setDisplayRangeOfScheduler(now, 'day');
        // TODO: fix types, use exposed interface?
        (this.scheduler.tbar.getWidgetById('date') as any).value = now;
      }
    }

Should the value interfaces be exposed in the types or is there a recommended way to achieve this instead?


Post by mats »

The typings look correct to us, can you please specify what type errors you are getting? What version are you using?

/**
         * Get/set value, which can be set as a Date or a string but always returns a Date. If a string is
         * specified, it will be converted using the specified <a href="https://bryntum.com/products/grid/docs/api/Core/widget/DateField#config-format">format</a>
         */
        value: string|Date

Post by Animal »

https://bryntum.com/products/scheduler/docs/api/Core/widget/Widget doesn't have value because it's just a generic widget base class

https://bryntum.com/products/scheduler/docs/api/Core/widget/Field does though.

And type: 'datefield' is a specialized class of Field.


Post by clemenshimmer »

Core.widget.Widget doesn't have value because it's just a generic widget base class

Core.widget.Field does though.

And type: 'datefield' is a specialized class of Field.

Yeah, this is the problem I'm having, I access the field by getWidgetById, which returns a Widget:

 (this.scheduler.tbar.getWidgetById('date') as any).value = now; 

I'll just need to cast the widget as Field instead of any; there's no proper way to infer the type with just this information without some complex type mapping.


Post Reply