RUBY:edit.html.haml禁用输入编辑

问题描述 投票:0回答:1

我想禁用输入,以便用户单击编辑后就无法读取。

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)}
html ruby haml
1个回答
0
投票

选项disabled: true将禁用表单上的字段,因此它将仅显示值,不允许对其进行编辑。

    = text_field :student_id, :student_id, :maxlength => 6, disabled: true, :class => 'form-control'

[如果要使其不可读,在编辑时仅在添加新学生时可用,则可以在edit.html.haml上使用条件,即,如果您正在重新使用此模板,则可以使用@student new_record?

= form_tag student_path(@student), :method => :put do
  - if @student.new_record?
    = render :partial => 'student_form'
© www.soinside.com 2019 - 2024. All rights reserved.