如何在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_form.html.haml:

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

如果您在其他地方重用部分student_form,并希望在该地方可编辑,则可以通过在locals中传递此值,就像在其他部分中一样。

© www.soinside.com 2019 - 2024. All rights reserved.