Skip to content

Instantly share code, notes, and snippets.

@donayama
Created February 9, 2012 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donayama/1780454 to your computer and use it in GitHub Desktop.
Save donayama/1780454 to your computer and use it in GitHub Desktop.
InputDialog(KeyPad) for Titanium Mobile
#-----------------------------------------------------------------------
# InputDialog for Titanium Mobile (by @donayama)
#
# Original JS Version by @k0sukey
# http://k0sukey.tumblr.com/post/17082188960
#-----------------------------------------------------------------------
# Sample
#-----------------------------------------------------------------------
# InputDialog = require 'InputDialog'
#
# btn.addEventListener 'click', (e) ->
# InputDialog.Show win, {hintText: 'このまま入力してください'}, (text) ->
# alert text
#
# InputDialog.Show win, {returnKeyType: Ti.UI.RETURNKEY_DONE}, (text) ->
# alert text
#-----------------------------------------------------------------------
exports.Show = (_window, _option, _callback) ->
#
# View (masking)
#
mask = Ti.UI.createView
backgroundColor: 'gray'
opacity: 0.75
_window.add(mask)
mask.addEventListener 'click', () ->
removeObjects()
removeObjects = ->
_window.remove dummy
_window.remove mask
returnText = () ->
text = tf.value
removeObjects()
_callback text
#
# TextField (in dummy's keyboardtoolbar)
#
tf = Ti.UI.createTextField
width: 300
height: 32
value: _option?.defaultValue ? ''
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED
hintText: _option?.hintText ? ''
returnKeyType: _option?.returnKeyType ? Ti.UI.RETURNKEY_DONE
tf.addEventListener 'return', returnText
#
# TextField (dummy)
#
dummy = Ti.UI.createTextField
top: 0
left: 0
width: 320
height: 50
value: _option?.defaultValue ? ''
visible:false
opacitry: 0.0
keyboardToolbar: [tf]
keyboardToolbarColor: '#999'
keyboardToolbarHeight: 40
hintText: _option?.hintText ? ''
returnKeyType: _option?.returnKeyType ? Ti.UI.RETURNKEY_DONE
_window.add dummy
dummy.addEventListener 'change', () ->
if tf.value != dummy.value
tf.value = dummy.value
dummy.addEventListener 'return', returnText
dummy.focus()
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment