Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk-edit-fill class not coming for FileField in Bulk_edit option #3700

Open
vmathurpaytm opened this issue Dec 29, 2021 · 0 comments
Open

Comments

@vmathurpaytm
Copy link

vmathurpaytm commented Dec 29, 2021

Model

file_item = models.FileField(blank=False, verbose_name=_('ABC'),)

Admin

bulk_list_display = ['file_item']

Expected behaviour

Want this file field to be copied over selected assets for bulk_edit

Actual behaviour

copy button is missing (class=bulk-edit-fill is not applied) over selected assets for bulk_edit for FileField

Screenshot 2021-12-30 at 2 59 29 AM

Tried Code (fill-fields.js)

`

      // Fill fields in bulk edit and split asset forms
      (function($) {
          $(function () {
              "use strict";
              // We use absolute positioning for toolbar therefore body must be relative
              $('body').css('position', 'relative');
              // Disable autocomplete without cluttering html attributes
              $('input').attr('autocomplete', 'off');
      
    var $fill_elements = $(
        'input[type=text]:not(.no-fillable), input[type=file]:not(.no-fillable), select, textarea, input[type=number]:not(.no-fillable), auto-complete:not(.no-fillable)',
        $('.bulk-edit.result-list')
    );
    var file_field_selector = function(input_id, $fields) {
        var current_href = $('#' + input_id).siblings("a").attr("href")
        var current_text = $('#' + input_id).siblings("a").text()
        $fields.siblings("a").attr("href", current_href);
        $fields.siblings("a").text(current_text);
    }
    var toggle_toolbar = function(element) {
        var $parent = element.closest('td');
        var $toolbar = $parent.find('.float_toolbar');
        if ($toolbar.length === 0) {
            var parent_height = $parent.height();
            $toolbar = $('#float_toolbar').clone();
            $toolbar.removeAttr('id');
            if (element[0].tagName === 'AUTO-COMPLETE') {
                $toolbar.data(
                    'input_id',
                    $parent.find('auto-complete')[0].id
                );
            } else {
                var $input = $parent.find('input, select, textarea');
                $toolbar.data('input_id', $input[0].id);
                $toolbar.data('input_type', $input[0].type);
            }
            $parent.append($toolbar);
            $parent.css('position', 'relative');
            $toolbar.css('top', parent_height / 2 - 12 + 'px');

            $toolbar.on('click', function(event) {
                event.preventDefault();
                var att_type = $(this).data('input_type')
                var input_id = $(this).data('input_id');
                var matcher = /(.*)-([0-9]+)-(.*)/;
                var results = matcher.exec(input_id);
                if (results) {
                    var $fields = $('[id^=' + results[1] + '-][id$=-' + results[3] + ']');
                    if (att_type === "file"){
                        file_field_selector(input_id, $fields)
                    }
                    else{
                        var value = $('#' + input_id).val();
                        $fields.val(value);
                    }
                    $fields.closest('td').addClass('fill-changed');
                    $fields.closest('td').animate({backgroundColor: 'white'});
                }
            });
            $toolbar.show();
        }
    };

    $fill_elements.each(function(i, element) {
        toggle_toolbar($(element));
    });
});
})(ralph.jQuery);

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant