Sha256: e4e9a36814de9b3dcee1bf34e68764e37c09805d239378aec52d83a1f4589487

Contents?: true

Size: 969 Bytes

Versions: 6

Compression:

Stored size: 969 Bytes

Contents

<%= form_for @post do |form| %>
  <p>
    <%= form.label :name %>
    <%= form.text_field :name %>
  </p>

  <p>
    <%= form.label :image %>
    <%= form.bard_file_field :image, accepts: "image", max: 100.kilobytes %>
  </p>

  <p>
    <%= form.label :images %>
    <%= form.bard_file_field :images, multiple: true, accepts: "image" %>
  </p>

  <p><%= form.submit "Submit" %></p>
<% end %>

<script type="module">
  import FormPersistence from "form-persistence"
  const form = document.querySelector("form")
  FormPersistence.persist(form, {
    beforeDeserialize: (form, data) => {
      [...form.querySelectorAll("bard-file")].forEach(bardFile => {
        bardFile.value = data[bardFile.name]
        delete data[bardFile.name]
      })
      return data
    },
    afterSerialize: (form, data) => {
      [...form.querySelectorAll("bard-file")].forEach(bardFile => {
        data[bardFile.name] = bardFile.value
      })
      return data
    },
  })
</script>

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bard-file_field-0.1.5 dummy/app/views/posts/form.html.erb
bard-file_field-0.1.4 dummy/app/views/posts/form.html.erb
bard-file_field-0.1.3 dummy/app/views/posts/form.html.erb
bard-file_field-0.1.2 dummy/app/views/posts/form.html.erb
bard-file_field-0.1.1 dummy/app/views/posts/form.html.erb
bard-file_field-0.1.0 dummy/app/views/posts/form.html.erb