Ruby on Railsでガラケーの文字種別をヘルパーでオプションを作り見やすいソースにしてみた
ガラケーサイトを制作する中で3キャリアそれぞれの文字種別を管理するヘルパーでオプションを作りそれを使うことによりより見やすいソースを書くことが出来た。
まずは3キャリアそれぞれが必要なコードは
まずdocomo
istyle="1"(全角かな) istyle="2"(半角カナ) istyle="3"(半角英字) istyle="4"(半角数字)
-wap-input-format:"*<ja:★>"; これは★の位置に入れる h=全角かな hk=半角カナ en=半角英字 n=半角数字
format="*A"(半角英字の大文字) format="*a"(半角英字の小文字) format="*N"(半角数字) format="*X"(半角英数の大文字) format="*x"(半角英数の小文字) format="*M"(全角かな) format="*m"(全角英字)
mode="hiragana"(全角かな) mode="katakana"(全角カナ) mode="alphabet"(半角英字) mode="numeric" (半角数字)
以上のようになっているが、docomoはHTMLとXHTMLで違うようです。
ここは気をつけなければいけないですね。
それを踏まえてヘルパーにmobile_helper.rbのようなものを作って
JPmobileと連動させて作って見ました。
def text_field_options(type, options = {}) hash = case type when :numeric istyle = 4 style = '-wap-input-format:"*<ja:n>"";-wap-input-format:*x;' mode = 'numeric' when :alphabet istyle = 3 style = '-wap-input-format:"*<ja:en>";-wap-input-format:*x;' mode = 'alphabet' end hash = case request.mobile when Jpmobile::Mobile::Docomo { :istyle => istyle, :style => style } when Jpmobile::Mobile::Au { :istyle => istyle } when Jpmobile::Mobile::Softbank { :istyle => istyle, :mode => mode } else {} end hash.merge(options) end
このようにすればパスワードの時やメールアドレス入力の時に短いオプションで綺麗に
間違いのないソースが書けました。
参考文献
http://www.abe-tatsuya.com/web_prog/mobile_web/input_attributes.php
http://webdirector.livedoor.biz/archives/51781969.html