puranjayjain / md-date-time-picker

An implementation of Material Design Picker components in vanilla CSS, JS, and HTML
https://puranjayjain.github.io/md-date-time-picker
Other
275 stars 77 forks source link

onOk event doesn't fire on input field #201

Closed Grasher134 closed 7 years ago

Grasher134 commented 7 years ago

I tried to add both click and onOk events to field. Click works fine, I see a popup, though it is kinda blurry. But when I hit ok - nothing happens.

<script type="text/javascript">
    var dialog = new mdDateTimePicker.default({
        type: 'date'
    });
    var toggleButton = document.getElementById('date-format');
    toggleButton.addEventListener('click', function() {
        dialog.toggle();
    });
    toggleButton.addEventListener('onOk', function() {
        this.value = dialog.time.toString();
    });
</script>
MelleB commented 7 years ago

I think you need to add

dialog.trigger = document.getElementById('date-format');
digitalkaoz commented 7 years ago

@MelleB is right, you have to add the trigger first, either

dialog.trigger = document.getElementById('date-format');

or

var dialog = new mdDateTimePicker.default({
        type: 'date',
        trigger : document.getElementById('date-format')
})