通过刺激控制器重置文件字段

发布于 2025-02-11 18:46:32 字数 489 浏览 0 评论 0原文

我有一种通过刺激控制器提交的表格。

#form.html.haml

= form_with url: my_url, multipart: true, data: { turbo_frame: 'document_table_content', turbo_action: 'advanced' } do |f|
  = f.file_field 'documents[files]', multiple: true, direct_upload: true, data: { 'dropzone-target' => 'input' }

#dropzone_controller.js

Rails.fire(this.form, "submit");

这起作用,我想在提交重置file_field后另外,我可以通过this.inputtarget ,但是我不知道如何从此表单字段。

I have a form which is submitted through stimulus controller.

#form.html.haml

= form_with url: my_url, multipart: true, data: { turbo_frame: 'document_table_content', turbo_action: 'advanced' } do |f|
  = f.file_field 'documents[files]', multiple: true, direct_upload: true, data: { 'dropzone-target' => 'input' }

#dropzone_controller.js

Rails.fire(this.form, "submit");

This works, I want additionally after submit to reset the file_field, I have the target through this.inputTarget but I don't know how to remove all files from this form field.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨笨の傻瓜 2025-02-18 18:46:32

对我来说似乎总是很奇怪,但是要实现文件输入的重置您必须重置表格!

document.querySelector('form').reset()

It has always seemed strange to me, but to achieve the reset of the file input you have to reset the form!

document.querySelector('form').reset()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文