LoginSignup
1
1

More than 5 years have passed since last update.

TextFieldからフォーカスを外したい

Last updated at Posted at 2014-12-14

http://qiita.com/yasunori/items/b990d206eaac0c351a19 +先輩のコードを参考にやってみたんですが挙動が少しおかしかったのでちょいと手を加えてみました

  • ソースコード
view
<Alloy>
  <Window onClick="blurKeyboard">
    <View id="container" layout="vertical">
      <TextField id="address"  onFocus="setKeyboardOwner" />
      <TextField id="password" onFocus="setKeyboardOwner" />
      <Button id="btn" />
    </View>
  </Window>
</Alloy>
controller
function setKeyboardOwner(e) {
  Ti.API.debug("setKeyboardOwner");
  currentKeyboardOwner = e.source;
  e.cancelBubble = true;
}

//キーボードを閉じる
function blurKeyboard(e) {
  Ti.API.debug("blurKeyboard");
  if(typeof(currentKeyboardOwner) !== 'undefined') {
    currentKeyboardOwner.blur();
  }
}

$.index.open();
tss
"TextField": {
  bubbleParent: false,
}

重要なのはtssのbubbleParent: falseです(これを追加する前と後で動作が変わっていたのでおそらくbubbleParentです)
親のviewにclickイベントを伝播させないのが重要だと思いました.はい.

ちなみにAndroid, iOSどちらも動きます.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1