Current Instance - JavaScript

Hi, I am trying to create a custom “Today” button in my calendar view.
The problem I have is that I don’t know how to reference the control itself from the “handler” function. The only input parameter is “event”, which in this case is of type “PointerEvent” and from it I can’t, or don’t know, how to get the instantiation of the control.
I have searched the documentation and forums and the closest thing is “activeInstance” but it doesn’t work. Here is an example of the code:

	    var opts = {
		controls: ['calendar','time'],
                dateFormat: 'D-MM-YYYY',
                timeFormat: 'H:mm:ss',
                returnFormat: 'iso8601'
                stepMinute: 5,
                stepSecond: 30,
                buttons: [
                    {
                        text: 'OK',
                        cssClass: 'icon-folder-ope',
                        handler: 'set',
                        keyCode: 'enter'
                    }, 
                    'cancel',
                    {
                        text: _locale['nowText'],
                        handler: function (event):void {
                            //necesito saber la instáncia
			    var inst = mobiscroll.activeInstance;
   			    inst.setVal(new Date());
			    inst.close();
                        },
                        keyCode: 'space'
                    }
                ]
		};
		mobiscroll.datepicker( jeweldatefield2, opts );

Screenshot_8

Thx.

Hi there,

Here’s how you can get the mobiscroll instance in JS: mobiscroll.datepicker('#your-picker');

Basically you just need to save it on initialization:

var opts = {
    controls: ['calendar', 'time'],
    dateFormat: 'D-MM-YYYY',
    timeFormat: 'H:mm:ss',
    returnFormat: 'iso8601',
    stepMinute: 5,
    stepSecond: 30,
    buttons: [{
            text: 'OK',
            cssClass: 'icon-folder-ope',
            handler: 'set',
            keyCode: 'enter'
        },
        'cancel',
        {
            text: _locale['nowText'],
            handler: function (event) {
                //necesito saber la instáncia
                inst.setVal(new Date());
                inst.close();
            },
            keyCode: 'space'
        }
    ]
};
var inst = mobiscroll.datepicker(jeweldatefield2, opts);

Hi Gabi, thank you for replying.

Yes, so there is no problem. The need arises for me because I’m making a generic custom control (with fixed custom options) and currently I can’t reference from “handler” to the instance because it will be dynamic, I can’t reference “this”.
I don’t know if I’m explaining myself… put another way “my - opts - is a template”.

I’ve rethought it and currently dispatch an event and, for now, this works for me.

Couldn’t the “event” and the “inst” be sent as a function parameter in a similar way to events?

Thx.

For us to understand your usage completely, we would need a greater insight to your project structure and custom controls. You are welcome to share some more details about your use case so I can create a feature request and add your voice to it.

Thank you!