お世話になります。
テーブルの入力をHTMLの画面で行うPGを作ります。
「今年」を入力すると、「来年」に1年後の値が自動で入力されるようにしたいです。
「今年」にOnchange を付けて javascript での実装を考えましたが、editでHTMLの要素を検証するとvalue属性が無く、「今年」の入力情報を取得出来ません。
何かうまい方法はありますでしょうか。
※以下はPGを抜粋したものです。indexから1レコードを取得した後の内容になります。
私の理解が低く、必要なものが抜けているかもしれません。
「○○の記述が無いけど??」といったことがありましたらお知らせください。
---edit(view)---------
<%= form_for @test do |f| %>
今年
<td class="td_txt">
<%= f.text_field :this_year, :class => "datepicker", :tabindex => 0 %>
登録ボタン
<td class="td_btn"> <%= f.submit h(translate(:create, :default => "update", :scope => [:railties, :scaffold])), :class=>"btna", :tabindex => -1 %> </td> <% end %>--controller----
class testsController < ApplicationController
#編集画面
def edit
begin
#データ取得
@test = Test.find(params[:id])
rescue ActiveRecord::RecordNotFound
#データなし
flash[:warning] = Configdata.find_by(name: 'notfound_message').data
#一覧画面へ
redirect_to get_back()
end
end
#更新画面
def update
@test = Test.find(params[:id])
begin ActiveRecord::Base.transaction() do if params[:commit] == translate(:create, :default => "Create", :scope => [:railties, :scaffold]) @test.updated_user_id = current_user.id @test.update(test_params) redirect_to get_back() else __#ファイル閲覧処理__ end end end
end
def test_params
params.require(:test).permit(:this_year,:next_year)
end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。