Month field on EXTJS 5.1
Asked Answered
P

3

5

I got this awesome fiddle https://fiddle.sencha.com/#fiddle/h5i from another stack overflow post (thanks igor). BUT I have one problem: the code doesn't work if I select extjs version 5.1, which is the version I use in my application. The problem is that when I click on a month or a year, the calendar just closes (you can try the behaviour by setting the version to 5.1 and running the fiddle again). I have tried to custom parts of the code, but nothing changed :s.

Anyone has any ideas of why this doesn't work with extjs 5.1, or how could i workaround the problem ?

Thanks in advance :) !

Prospero answered 28/1, 2015 at 16:20 Comment(2)
Works fine for me in ExtJs 5.1, using FireFoxTelegraph
OH !! Yes it works also on IE !! But it does not work on chrome !! So weird ^^'Prospero
Y
6

Somehow Chrome behavior is different. Try the following:

createPicker: function () {
    var me = this,
        format = Ext.String.format,
        pickerConfig;

    pickerConfig = {
        pickerField: me,
        ownerCmp: me,
        renderTo: document.body,
        floating: true,
        hidden: true,
        focusOnShow: true,
        minDate: me.minValue,
        maxDate: me.maxValue,
        disabledDatesRE: me.disabledDatesRE,
        disabledDatesText: me.disabledDatesText,
        disabledDays: me.disabledDays,
        disabledDaysText: me.disabledDaysText,
        format: me.format,
        showToday: me.showToday,
        startDay: me.startDay,
        minText: format(me.minText, me.formatDate(me.minValue)),
        maxText: format(me.maxText, me.formatDate(me.maxValue)),
        listeners: {
            select: { scope: me, fn: me.onSelect },
            monthdblclick: { scope: me, fn: me.onOKClick },
            yeardblclick: { scope: me, fn: me.onOKClick },
            OkClick: { scope: me, fn: me.onOKClick },
            CancelClick: { scope: me, fn: me.onCancelClick }
        },
        keyNavConfig: {
            esc: function () {
                me.collapse();
            }
        }
    };

    if (Ext.isChrome) {
        me.originalCollapse = me.collapse;
        pickerConfig.listeners.boxready = {
            fn: function () {
                this.picker.el.on({
                    mousedown: function () {
                        this.collapse = Ext.emptyFn;
                    },
                    mouseup: function () {
                        this.collapse = this.originalCollapse;
                    },
                    scope: this
                });
            },
            scope: me,
            single: true
        }
    }

    return Ext.create('Ext.picker.Month', pickerConfig);
}
Yeargain answered 5/3, 2015 at 22:25 Comment(1)
Is there any way to prevent the manual entry in this custom date field. i.e. i should be able to give value only via pickerSterculiaceous
P
1

Add properties:

onFocusLeave: Ext.emptyFn
Padraig answered 14/4, 2015 at 11:49 Comment(0)
A
0

Try this it works fine for me.

Ext.onReady(function() {
  Ext.define('Ext.form.field.Month', {
    extend: 'Ext.form.field.Date',
    alias: 'widget.monthfield',
    requires: ['Ext.picker.Month'],
    alternateClassName: ['Ext.form.MonthField', 'Ext.form.Month'],
    selectMonth: null,
    createPicker: function() {
      var me = this,
        format = Ext.String.format;
      return Ext.create('Ext.picker.Month', {
        pickerField: me,
        ownerCt: me.ownerCt,
        renderTo: document.body,
        floating: true,
        hidden: true,
        focusOnShow: true,
        minDate: me.minValue,
        maxDate: me.maxValue,
        disabledDatesRE: me.disabledDatesRE,
        disabledDatesText: me.disabledDatesText,
        disabledDays: me.disabledDays,
        disabledDaysText: me.disabledDaysText,
        format: me.format,
        showToday: me.showToday,
        startDay: me.startDay,
        minText: format(me.minText, me.formatDate(me.minValue)),
        maxText: format(me.maxText, me.formatDate(me.maxValue)),
        listeners: {
          select: {
            scope: me,
            fn: me.onSelect
          },
          monthdblclick: {
            scope: me,
            fn: me.onOKClick
          },
          yeardblclick: {
            scope: me,
            fn: me.onOKClick
          },
          OkClick: {
            scope: me,
            fn: me.onOKClick
          },
          CancelClick: {
            scope: me,
            fn: me.onCancelClick
          }
        },
        keyNavConfig: {
          esc: function() {
            me.collapse();
          }
        }
      });
    },
    onCancelClick: function() {
      var me = this;
      me.selectMonth = null;
      me.collapse();
    },
    onOKClick: function() {
      var me = this;
      if (me.selectMonth) {
        me.setValue(me.selectMonth);
        me.fireEvent('select', me, me.selectMonth);
      }
      me.collapse();
    },
    onSelect: function(m, d) {
      var me = this;
      me.selectMonth = new Date((d[0] + 1) + '/1/' + d[1]);
    }
  });

  Ext.create('Ext.form.field.Month', {
    format: 'F, Y',
    fieldLabel: 'Date',
    renderTo: Ext.getBody()
  });
});
Ashworth answered 15/9, 2018 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.