Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [solved] DateField Change Event

  1. #1

    Default [solved] DateField Change Event

    I am trying to get a DateField to emit an event when a date is actually selected, and not after the field loses focus:

    Code:
    var picker = new Ext.form.DateField({
            fieldLabel: 'Pick a date',
            value: new Date()
        });
    picker.on('change', MyCallbackFunction);
    This code only calls my function just before blur(as the documentation states for the change event). I have also tried the 'focus' event, with little success, as it only gets called when the field is focused by the user, and not after a date is selected.

    Basically I don't want to require the user to click outside of the field in order for their selected date to update the panels.

    I'm sure this is not a new problem, I couldn't find any solutions quickly. Any ideas?

  2. #2

    Default

    The API docs for dateField (and its parent class TriggerField) do not list an event for such behavior, so either it is not supported or is not documented. I do also think that this would be a usefull event to have for all triggerField based fields, probably in the form of a 'select' event like what comboBox has.
    Other than this appeal to the devs to add this as a feature, I cannot give any help other than suggesting to code it in yourself though

  3. #3

    Default

    Thanks for your input, I will resort to coding it myself if there are no solutions readily available. I agree a select event would be very nice to have.

  4. #4

    Default

    Curiosity got the better of me so I looked to see if there was a quick hack that will work until a more permanant solution is found:
    Code:
    {
      xtype:'datefield',
      listeners: {
        render: function(){
          this.menuListeners.select = function(m, d){
            this.setValue(d);
            console.log('date selected')
          }
        }
      }
    }
    enjoy

  5. #5

    Default

    Wow, thanks for your help, it works great, the only issue is if I have 2 datefields, it doesn't work for the second one. This is probably because I don't totally understand what that code does, so please excuse my newness to Ext.

    Is that a listener on the datefield type?

    Thanks for your help again.

  6. #6

    Default

    yes, that is a lazyRender config for a single dateField instance. this is not a global override or anything like that, you would need to set it for each dateField you have.

  7. #7

    Default

    Quote Originally Posted by kekoav View Post
    Wow, thanks for your help, it works great, the only issue is if I have 2 datefields, it doesn't work for the second one.

    Actually it does work for all fields-- my bad. I noticed I only need to add that listener section to one datefield, and it applies to all the others. I guess I should learn a little more how the listeners work... it seems they work differently than the on('event') type of handlers?

    Anyhow thanks very much for your help it works great now! I just added the following to my config for the datefield:

    Code:
    listeners: {
         render: function(){
              this.menuListeners.select = function(m, d){
                    this.setValue(d);
                    MyCallbackFunction()
               }
          }
     }

  8. #8

    Default

    Normally adding a listener this way is the same as adding it with addListener (for which 'on' is a shortcut). Perhaps the fact that we are replacing fairly low level function is causing it to act differently.

  9. #9
    Sencha User
    Join Date
    Mar 2008
    Posts
    50

    Default

    aaaa....
    thank you very much!!
    im looking for this event listener for weeks...

  10. #10
    Sencha User
    Join Date
    Mar 2008
    Posts
    50

    Default

    solved..thx

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •