famo.us: how to handle textbox.onchange events

只愿长相守 提交于 2019-12-31 05:36:13

问题


I don't see any tutorials with text input on famo.us university. How can I add a text box surface to my app and handle onchange events?


回答1:


It is a bit hard to understand what you are looking to do.. But lets start out with your first question. There is currently no onchange handler option so if you want it now, you can write a subclass of InputSurface. By overriding the deploy function, while still calling InputSurface's deploy function, we can add the functionality we want, without messing around to much!

Here is a way you could add an onchange handler to a subclass of InputSurface. Just remember again onchange is only triggered after the InputSurface is blurred.

Good Luck!

var Engine            = require('famous/core/Engine');
var Surface           = require('famous/core/Surface');
var StateModifier     = require('famous/modifiers/StateModifier');
var EventHandler      = require('famous/core/EventHandler')
var InputSurface      = require('famous/surfaces/InputSurface')


function MyInputSurface(options) {
    InputSurface.apply(this, arguments);
    this.onchange = options.onchange;
    this._superDeploy = InputSurface.prototype.deploy;
}

MyInputSurface.prototype = Object.create(InputSurface.prototype);
MyInputSurface.prototype.constructor = MyInputSurface;

MyInputSurface.prototype.deploy = function deploy(target) {
  target.onchange = this.onchange;
  this._superDeploy(target);
};

var context = Engine.createContext();

var onchangeFunction = function(){ console.log("Text Changed!"); }

var myInput = new MyInputSurface({
  size: [200,60],
  onchange: onchangeFunction
})

context.add(new StateModifier({origin:[0.5,0.5]})).add(myInput);



回答2:


You could just compose 'select' element and put it as content to the surface. After that, create listener for this surface: surface.on('deploy', method). In that method find created 'select' via document.querySelector and set onchange handler in which just emit 'change' event to the this._eventOutput/whatever.

Actual coffee file see here: https://gist.github.com/extempl/346c045c6c71b3345ac3



来源:https://stackoverflow.com/questions/23495176/famo-us-how-to-handle-textbox-onchange-events

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!