Created
July 23, 2009 09:03
-
-
Save oukayuka/152567 to your computer and use it in GitHub Desktop.
Setting default input mode to text form for mobile client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView | |
module Helpers | |
module FormHelper | |
alias :text_field_without_inputmode :text_field | |
# ==== Options | |
# * <tt>:inputmode</tt> - 入力モード。Jpmobile::InputMode::HIRAGANA-全角ひらがな、Jpmobile::InputMode::HANKAKUKANA-半角カナ、Jpmobile::InputMode::ALPHABET-半角英字、Jpmobile::InputMode::NUMERIC-半角数字 | |
# ==== Examples | |
# text_field_tag(:user, :name, :size => 20, :inputmode => Jpmobile::InputMode::HIRAGANA) | |
# # => <input id="name" name="name" type="text" size="20" istyle="1" style="-wap-input-format:"<ja:h>""> | |
def text_field(object_name, method, options = {}) | |
ActionView::Helpers.add_inputmode_option(options, request) | |
text_field_without_inputmode(object_name, method, options) | |
end | |
alias :password_field_without_input_mode :password_field | |
# ==== Options | |
# * <tt>:inputmode</tt> - 入力モード。Jpmobile::InputMode::HIRAGANA-全角ひらがな、Jpmobile::InputMode::HANKAKUKANA-半角カナ、Jpmobile::InputMode::ALPHABET-半角英字、Jpmobile::InputMode::NUMERIC-半角数字 | |
# ==== Examples | |
# password_field_tag(:user, :password, :size => 20, :inputmode => Jpmobile::InputMode::ALPHABET) | |
# # => <input id="user_password" name="user[password]" type="password" value="#{@user.password}" size="20" istyle="3" style="-wap-input-format:"*<ja:en>""> | |
def password_field(object_name, method, options = {}) | |
ActionView::Helpers.add_input_mode_option(options, request) | |
password_field_without_input_mode(object_name, method, options) | |
end | |
end | |
module FormTagHelper | |
alias :text_field_tag_without_inputmode :text_field_tag | |
# ==== Options | |
# * <tt>:inputmode</tt> - 入力モード。Jpmobile::InputMode::HIRAGANA-全角ひらがな、Jpmobile::InputMode::HANKAKUKANA-半角カナ、Jpmobile::InputMode::ALPHABET-半角英字、Jpmobile::InputMode::NUMERIC-半角数字 | |
# ==== Examples | |
# text_field_tag('name', nil, :inputmode => Jpmobile::InputMode::HIRAGANA) | |
# # => <input id="name" name="name" type="text" istyle="1" style="-wap-input-format:"<ja:h>""> | |
def text_field_tag(name, value = nil, options = {}) | |
ActionView::Helpers.add_inputmode_option(options, request) | |
text_field_tag_without_inputmode(name, value, options) | |
end | |
end | |
def self.add_inputmode_option(options, request) | |
case request.mobile | |
when Jpmobile::Mobile::Docomo | |
case options[:inputmode] | |
when Jpmobile::InputMode::HIRAGANA | |
options[:istyle] = '1' # 全角かな | |
options[:style] = '-wap-input-format:"*<ja:h>"' # 全角かな | |
when Jpmobile::InputMode::HANKAKUKANA | |
options[:istyle] = '2' # 半角カナ | |
options[:style] = '-wap-input-format:"*<ja:hk>"' # 半角カナ | |
when Jpmobile::InputMode::ALPHABET | |
options[:istyle] = '3' # 英字 | |
options[:style] = '-wap-input-format:"*<ja:en>"' # 英字/半角文字 | |
when Jpmobile::InputMode::NUMERIC | |
options[:istyle] = '4' # 数字 | |
options[:style] = '-wap-input-format:"*<ja:n>"' # 数字/半角文字 | |
end | |
when Jpmobile::Mobile::Au | |
case options[:inputmode] | |
when Jpmobile::InputMode::HIRAGANA | |
options[:istyle] = '1' # 全角かな | |
options[:style] = '-wap-input-format:*M;' # 全角かな | |
when Jpmobile::InputMode::HANKAKUKANA | |
options[:istyle] = '2' # 半角カナ | |
options[:style] = '-wap-input-format:*M;' # 全角かな | |
when Jpmobile::InputMode::ALPHABET | |
options[:istyle] = '3' # 英字 | |
options[:style] = '-wap-input-format:*m;' # 英字/半角文字 | |
when Jpmobile::InputMode::NUMERIC | |
options[:istyle] = '4' # 数字 | |
options[:style] = '-wap-input-format:*N;' # 数字/半角文字 | |
end | |
when Jpmobile::Mobile::Softbank | |
case options[:inputmode] | |
when Jpmobile::InputMode::HIRAGANA | |
options[:mode] = 'hiragana' # 全角かな | |
options[:istyle] = '1' # 全角かな | |
options[:style] = '-wap-input-format:"*<ja:h>"' # 全角かな | |
when Jpmobile::InputMode::HANKAKUKANA | |
options[:mode] = 'hankakukana' # 半角カナ | |
options[:istyle] = '2' # 半角カナ | |
options[:style] = '-wap-input-format:"*<ja:hk>"' # 半角カナ | |
when Jpmobile::InputMode::ALPHABET | |
options[:mode] = 'alphabet' # 英字 | |
options[:istyle] = '3' # 英字 | |
options[:style] = '-wap-input-format:"*<ja:en>"' # 英字/半角文字 | |
when Jpmobile::InputMode::NUMERIC | |
options[:mode] = 'numeric' # 数字 | |
options[:istyle] = '4' # 数字 | |
options[:style] = '-wap-input-format:"*<ja:n>"' # 数字/半角文字 | |
end | |
end | |
options.delete(:inputmode) | |
end | |
end | |
end | |
module Jpmobile | |
module InputMode | |
HIRAGANA = 1 # 全角ひらがな | |
HANKAKUKANA = 2 # 半角カナ | |
ALPHABET = 3 # 半角英字 | |
NUMERIC = 4 # 半角数字 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment