How to implement JS EventListener on specific fields with Sugar10?

I´ve a problem to enable onChange Events within Create/Edit a Opportunity.

I have these 3 fields:

- invoicestartdate1_c (a date with datepicker)
- runtime_c (a integer field which hold the value for "how much month")
- invoiceenddate1_c (a date with datepicker)

What i would achive:

If the user change the field "invoicestartdate1_c" or the field "runtime_c" the field "invoiceenddate1_c" should be new calculated and set.

All should happen in the frontend.

Current solution seems to work fine so far - but the datepicker of the target field shows the new date only on the second click. Is there a way to "trigger refresh" for the datepicker field?

    initialize: function (options) {
        this._super('initialize', [options]);
        this.model.on('change:runtime1_c',this._updateInvoiceEndDate);
        this.model.on('change:invoicestartdate1_c',this._updateInvoiceEndDate);
    },

     _updateInvoiceEndDate: function(model)
     {
         if ($('[name="save_button"]').is(":visible")) {
            runtime = model.get("runtime1_c");
            startdate = model.get("invoicestartdate1_c");
            if (parseInt(runtime) > 0 && startdate !== undefined) {
                console.log(runtime, startdate)
                model.set('invoiceenddate1_c', startdate);
            }
        }
    },

Parents Reply Children