2

I would like to implement a clear button showed on popup in mobiscroll date picker There is an option to use button3, however I'm not able to clear the input and hide the scroller.

jQuery(this).mobiscroll({
        preset: 'date',
        theme:'ios',
        button3Text:'clear',
        button3: function(input, inst){
            jQuery(this).val();
            inst.close();
        }})

I was trying use the input and inst parameter from function. Unfortunately I'm not able to make it work.

Could you plese help?

Thanks Lucas

hs.chandra
  • 707
  • 1
  • 7
  • 19
Lucas
  • 31
  • 5

2 Answers2

1

I already solve the problem. I couldn't get the instance but when I save the object first

 var thisPicker = jQuery(this); 

and on button3 get the instance,

var inst = thisPicker.mobiscroll('getInst');

everything works fine.

Whole code...

// Date mobiscroll picker init
jQuery(".datepicker").each(function (index, element) {

    var thisPicker = jQuery(this);
    jQuery(this).mobiscroll({
        preset: 'date',
        theme:'ios',
        display : 'bottom',
        button3Text:'X',
        button3: function(){
            var inst = thisPicker.mobiscroll('getInst');
            thisPicker.val('');
            inst.cancel();

        },

    });
});
Lucas
  • 31
  • 5
1

Just found out that there is an option to enable "clear" button from within mobiscroll config:

http://docs.mobiscroll.com/2-15-1/mobiscroll-core#!opt-buttons

Buttons to display. Predefined buttons are: 'set', 'clear', 'cancel'. Custom buttons can also be specified:

Hugo Silva
  • 6,748
  • 3
  • 25
  • 42
ikarami
  • 66
  • 2