我想禁用输入,因此一旦用户单击“编辑”,该输入就不可编辑。
student_form.html.haml
:
%div{:class => 'form-group row'}
%div{:class => 'form-group col-3'}
= label :student_id, :student_id, 'Student Id'
= text_field :student_id, :student_id, :maxlength => 6, :class => 'form-control'
edit.html.haml
:
= form_tag student_path(@student), :method => :put do
= render :partial => 'student_form'
= submit_tag 'Save Changes', :class => 'btn btn-primary'
%p
= render partial: 'shared/cancel_button', locals: {path: student_path(@student)}
答案 0 :(得分:0)
您可以在disabled: true
中使用text_field
选项,以禁用表单上的字段,因此它将仅显示值,而不允许对其进行编辑。
student_form.html.haml:
= text_field :student_id, :student_id, :maxlength => 6, disabled: true, :class => 'form-control'
如果您要在其他地方重用部分student_form
,并且希望在那里进行编辑,则可以通过locals
传递此值,就像在其他部分中一样。