Feedback wanted: generic field:focus/change/blur and field:render/show events #147

wants to merge 3 commits into


None yet
6 participants

drd commented Oct 15, 2012

The problem:

I want to be able to update the entire form when any individual field is focused/blurred/changed and also to be able to configure and register event handlers on individual fields as they are rendered

The solution:

I've added generic field:focus, field:change, and field:blur events which get triggered when any editor is focused, changed or blurred. Also, I've added field:render and field:show. I've added tests for these events.

The quandary:

Unlike existing bbf events which bubble the editor, these events pass the field as the second argument to handlers. I don't like this inconsistency, but editors don't have a reference to the field and I needed to style the field in response to these events. There are a few solutions:

  • add a field reference to editors
  • add the editor as the 2nd argument, and the field as a third argument
  • or i can just look up the field in the form based on the name, and have these events have the same signature as the others

philfreo commented Oct 15, 2012

In many of the custom editors that I've written I've wanted access to the field - seems like providing that in a general purpose way would be a good solution.


drd commented Oct 15, 2012

rebased to master


powmedia commented Nov 22, 2012

I've created another issue about changing the arguments passed into event callbacks which could help sort the inconsistencies:


Is it still considered? It would really help me to DRY my views.
I would like to revalidate fields on blur without the need to list them all inside listenTo call.

@listenTo formView, 'name:blur email:blur client:blur', (form, editor) ->

It creates unnecessary overhead to keep that events list in sync with the schema that defines validators. (e.g. I can add validator to a new field, but forget to add event for that field in that list)


fonji commented Oct 20, 2014

+1. I had to do something similar.


exussum12 commented Oct 20, 2014

I would like to revalidate fields on blur without the need to list them all inside listenTo call

I do this by listening to all and filtering blur events (check if it ends with :blur)


powmedia commented Oct 20, 2014

If anyone is up for updating this PR off the latest code in master I'll merge this in


exussum12 commented Oct 20, 2014

  form.on('all', function(type, form, edited) {
      if (type.endsWith(":blur")) {

where endsWith is defined as

   String.prototype.endsWith = function(suffix) {
      return this.indexOf(suffix, this.length - suffix.length) !== -1;

It seems strange to trigger 2 events which are essentially the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment