我正在学习Rails,我遇到了一个问题。
当我提交表单时,我会收到一条弹出消息进行确认。
如果我按Ok
,则表单将提交,按钮将被禁用,其工作正常。
但是当我取消弹出确认时,提交按钮也会在不应该被禁用时被禁用。
我想在提交表单后1分钟禁用“提交”按钮,如果取消弹出确认,则应激活提交按钮。
请帮我解决问题。
<%= f.submit 'Submit', :class => "btn btn-yellow", data: { disable_with: "Please wait..." }%>
答案 0 :(得分:1)
我想date_disable_with
最适合这种情况,因为它会在表单提交完成之前禁用提交按钮。
如果您想要完全禁用提交按钮1分钟,则需要使用javascript。
要让date_disable_with
工作,您需要在页面中加入jquery和jquery-ujs
答案 1 :(得分:0)
您试试data_disabled_with
吗?它会在第一次点击后自动禁用提交按钮,但如果取消则会返回启用状态。
submit_tag
# => <input name="commit" data-disable-with="Save changes" type="submit" value="Save changes" />
submit_tag "Edit this article"
# => <input name="commit" data-disable-with="Edit this article" type="submit" value="Edit this article" />
submit_tag "Save edits", disabled: true
# => <input disabled="disabled" name="commit" data-disable-with="Save edits" type="submit" value="Save edits" />
submit_tag "Complete sale", data: { disable_with: "Submitting..." }
# => <input name="commit" data-disable-with="Submitting..." type="submit" value="Complete sale" />
submit_tag nil, class: "form_submit"
# => <input class="form_submit" name="commit" type="submit" />
submit_tag "Edit", class: "edit_button"
# => <input class="edit_button" data-disable-with="Edit" name="commit" type="submit" value="Edit" />
submit_tag "Save", data: { confirm: "Are you sure?" }
# => <input name='commit' type='submit' value='Save' data-disable-with="Save" data-confirm="Are you sure?" />