Our pure JavaScript Scheduler component


Post by galtonova »

eventEdit extraWidgets value property does not set a default value for EventEdit forms if name parameter matches a property from eventRecord property. If I give some random name to name property, it sets a default value but then doesn't set proper field.
        extraWidgets: [
          {
            label: 'Agency',
            type: 'text',
            name: 'agency',
            items: ['Booking.com', 'Expedia.com', 'Online'],
            value: 'Booking.com'
            required: true,
            editable: false,
          },
          {
            label: 'Board Type',
            type: 'text',
            name: 'boardName',
            items: ['BB', 'HB', 'FB', 'AI'],
            value: 'BB'
            required: true,
            editable: false,
          }
        ]
agency and boardName properties are part of my mock event object. However I if change
name: 'agency'
into
name: 'agencyQWE'
it sets the default value as 'Booking.com' on Event Edit form.

Post by mats »

Any chance you can upload a runnable test case that we can inspect here? So we see your data too etc (dummy data is fine)

Post by galtonova »

Sure. Here's a repo that shows this issue:
https://github.com/galtonova/BryntumSch ... faultValue

And also a live gh-pages site:
https://galtonova.github.io/BryntumSche ... aultValue/

Try creating a new event by dragging around. You will see that, in the newly created event, agencyQWE field will have default value but agency field will not.

Also a screenshot and related codes:
https://github.com/galtonova/BryntumSch ... e/issues/1

Post by pmiklashevich »

That is intentional behavior. When EventEdit.loadRecord is called it sets record to the editor form. It loops through the widgets and sets values based on record field. It's done in lib/Common/widget/Container.js
    set record(record) {
        const widgets = this.queryAll(w => w.name),
            len = widgets.length;

        for (let i = 0; i < len; i++) {
            let widget = widgets[i],
                name = widget.name;

            if (name in record) {
                widget.value = record[name];
            }
        }

        this._record = record;
    }
If you set a debugger there you'll see that default value is set correct. But since name is found in the record it sets to the widget's value. In your test case when you create new event the record field is empty, that's why you see empty field in the event editor.

Pavlo Miklashevych
Sr. Frontend Developer


Post by galtonova »

I see. So, what's the proper way to set default record for new events?

Post by pmiklashevich »

You can set defaultValue for your event model field definition. Please check the docs here: https://www.bryntum.com/docs/scheduler/ ... EventModel

and also there are 2 hooks in before event is added (beforeEventAdd event and onEventCreated template function) where you can set some field values, assign to a resource etc. But I've just found out that they are inconsistent at the moment. I've created a ticket to get it fixed: https://app.assembla.com/spaces/bryntum/tickets/7322

Pavlo Miklashevych
Sr. Frontend Developer


Post by galtonova »

Thanks!

Post Reply