yoqw/web/cms/app/components/form-input-datetimepicker.js
Shaun Chyxion 264af78bbd add sound
2020-08-16 15:44:47 +08:00

32 lines
1004 B
JavaScript

import BaseFormInput from './form-field';
import $ from 'jquery';
export default BaseFormInput.extend({
format: 'YYYY-MM-DD HH:mm:ss',
didReceiveAttrs() {
const me = this;
me._super(...arguments);
if (!me.get('value')) {
const val = me.get('model.' + me.get('name'));
me.set('value', val ? (/^\d+$/.test(val) ? +val : val) : new Date().getTime());
}
me.set('valueInput', moment(me.get('value')).format(me.get('format')));
},
didInsertElement() {
let me = this;
$(me.element).find('input').datetimepicker({
format: me.get('format'),
showClear: true,
autoclose: true,
todayHighlight: true
})
.on('dp.change', function(ev) {
me.setVal(ev.date.toDate().getTime());
})
//show datepicker when clicking on the icon
.next().on(ace.click_event, function() {
$(this).prev().focus();
});
}
});