Skip to content

Blur and Focus Events No Longer Fire for Text Fields #4350

@amber-cd

Description

@amber-cd

Blur event binding which previously worked is no longer working

I've been working on upgrading our Blockly implementation to the newest version, past the formalization of the custom fields API, but I'm running into an issue. In our previous implementation, we were using "blur" events in order to trigger some actions when a field lost focus. (I was doing this more or less as a workaround for this old issue, as we need to run some computation-intensive updates when the value change for a field is "committed." Now, however, the event no longer appears to fire, nor does "focus." I know I'm binding it correctly because a dummy mousedown event fires off correctly.

To Reproduce

  1. Create a custom Field which extends FieldTextInput
  2. Add the following to bindEvents_:
Blockly.CustomField.prototype.bindEvents_ = function() {
  Blockly.CustomField.superClass_.bindEvents_.call(this);
  this.onBlurWrapper_ =
    Blockly.bindEvent_(this.getClickTarget_(), 'blur', this, function(){
      console.log('Calling on blur');
    });
  this.onFocusWrapper =
    Blockly.bindEvent_(this.getClickTarget_(), 'focus', this, function(){
      console.log('Calling on focus');
    });
  this.onMDWrapper =
    Blockly.bindEvent_(this.getClickTarget_(), 'mousedown', this, function(){
      console.log('Calling mousedown');
    });
};
  1. Load the field on a block and then click in and out.

(Note: this replicates using both bindEvent_ and bindEventWithChecks_.)

Expected behavior
I would expect to see "Calling on focus" logged to the console when the field is focused and "Calling on blur" when the field loses focus.

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser Chrome
  • Version 85.0.4183.83 (Official Build) (64-bit)

Additional context

This worked before the upgrade. We ran into some other issues involving the select element being hidden until we changed its z-index, so I suspect there was some "under the hood" change made to how text fields were implemented which is interfering with these events. This is, again, basically a workaround in order to fire off functionality only when a change is committed vs, as the user is typing, so if there is some alternate way to do that which I have missed in my reading, please do let me know that.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions