LoginSignup
8
10

More than 5 years have passed since last update.

フォームを初期化するボタンをRailsで使う

Posted at

フォームのインプット要素を全部消して空白にしてくれるすごいボタンをjavascriptで作る前に<input type="reset">と書いてみるべきである。
Railsにはsubmit_tagtext_field_tagなどがあるが、何故かreset_tagがない。
どうしてもresetボタンが欲しい夜は、以下のようなものを用いる。

helpers/application.rb
def reset_tag(value = "Reset form", options = {})
  options = options.stringify_keys
  tag :input, { "type" => "reset", "value" => value }.update(options)
end

パクリ元

Rails / ActionView /../ form_tag_helper - Github

8
10
1

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
8
10