Author Topic: Bug? ComboBox onEditTextUpdated undefined  (Read 4534 times)

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Bug? ComboBox onEditTextUpdated undefined
« on: 2015 January 02 06:00:00 »
The event handler ComboBox.onEditTextUpdated is supposed to have a text parameter, but it is always undefined.
Also it seems that the onEditTextUpdated is called before onItemSelected when we select an item. This is possibly a recent change. The problem is that it is not possible to set a custom text depending on the selection (for example if the choice presented to the user has a comment part, but we do not want the comment part when the user select an item).
-- bitlit

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Bug? ComboBox onEditTextUpdated undefined
« Reply #1 on: 2015 January 02 14:10:19 »
Quote
The event handler ComboBox.onEditTextUpdated is supposed to have a text parameter, but it is always undefined.

This is actually a documentation bug. The description of this event handler should be:

void ComboBox.onEditTextUpdated()

So the onEditTextUpdated() handler receives no arguments. The reason for this is that the current text in the ComboBox is already available as the property:

String ComboBox.editText

so making a duplicate to pass it to an event handler of the same object is a nonsense. I'll fix this item description in the next version.

Quote
Also it seems that the onEditTextUpdated is called before onItemSelected when we select an item.

The order of calls to different event handlers of a given object is always unspecified and can be altered arbitrarily by the PJSR and PCL engines. You should never write code that depends on a specific order or sequence of calls to event handler functions.

In your case it seems that you don't need to use the  onEditTextUpdated() handler. You only need onItemSelected(). For example:

   this.combo.onItemSelected = function( itemIndex )
   {
      let s = this.itemText( itemIndex );
      // ... do something with the item text in variable s
      this.editText = s;
   };


Let me know if this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: Bug? ComboBox onEditTextUpdated undefined
« Reply #2 on: 2015 January 05 06:41:44 »
This helps, thanks.
I also need the onEditTextUpdated and I need to know if this was called by a select or an edit by the user.  I added a work around in onEditTextupdated  that check if the text is one of the allowed selections, in which case I ignore it. Works fine
-- bitli