Frage

Update I think I might have it figured out. I was using an old bacon.js version, which might have been part of the problem. I'll update later as I figure out if I have it. Here's the partially working version: http://cdpn.io/yfxDA

I'm trying to call a function every time an element loses focus (an input but in the below example I'm using a div).

This is what I tried:

var $on = $('div')
$on.asEventStream('focusout').subscribe(alert('no!'))

and

var $on = $('div')
$on.asEventStream('focusout').onValue(alert('no!'))

They both work the first time but then stop working. Is there a way to get this to work?

Eventually I would like to merge focusin/focusout and perform a side-effect.

War es hilfreich?

Lösung

It looks like I just needed the most up to date version of the software. Here's what the code looks like now:

var $on = $('div')
var $h = $('div input')
var d = 'contains'

$h.val(d)
var f = function(arg){
  return ($h.val() === d) ? '' : d
} 

$on.asEventStream('focusout').merge($on.asEventStream('focusin')).toProperty().assign($h, 'val', f)

Andere Tipps

I works just fine with the latest version: http://codepen.io/anon/pen/xLHyq

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top