Sha256: e5d453bea334239c6e09a648b174497af1cf2aaa65d04ba191e6b26156f64cc9

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

<div class="field-unit__label">
  <%= f.label field.attribute %>
</div>
<div class="field-unit__field">

  <% _group_id = "gid_#{SecureRandom.alphanumeric}" %>

  <% field.values.each do |v| %>
    <%= text_field_tag(
        nil,
        v,
        name: "#{f.object_name}[#{field.attribute}][]",
        class: _group_id,
    )
    %>

  <% end %>

  <%= text_field_tag(
      nil,
      '',
      name: "#{f.object_name}[#{field.attribute}][]",
      class: _group_id,
    )
  %>

  <%= button_tag(
      '+',
      onclick: 'var $l = $(".' + _group_id + '").last(); $l.clone(false).insertAfter($l).val(""); return false;',
    )
  %>

<script>
  (function() {
    var group_selector = '.<%= _group_id %>'

    document.addEventListener("DOMContentLoaded", function(evt) {

      var $f = $(group_selector).parents('form');

      $f.on('submit', function() {
        // Filter empty fileds before submit
        $(group_selector).filter(function() {
          return !this.value;
        }).removeAttr('name');
      });
    });
  })()
</script>
</div>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
administrate-field-list-0.0.6 app/views/fields/list/_form.html.erb
administrate-field-list-0.0.5 app/views/fields/list/_form.html.erb
administrate-field-list-0.0.4 app/views/fields/list/_form.html.erb