Ticket #13614: 13614.filterselect-webkit-bug.diff

File 13614.filterselect-webkit-bug.diff, 4.7 KB (added by Julien Phalip, 13 years ago)
  • django/contrib/admin/static/admin/js/SelectFilter2.js

    diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js
    index 2eb67e8..2b77113 100644
    a b window.SelectFilter = {  
    2121            return;
    2222        }
    2323        var from_box = document.getElementById(field_id);
    24         from_box.id += '_from'; // change its ID
     24
     25        // Create a clone to keep the actual values to be sent with the form
     26        var real_box = $(from_box).clone().insertBefore(from_box).hide();
     27
     28        from_box.id += '_from';
     29        from_box.name += '_from';
    2530        from_box.className = 'filtered';
    2631
    2732        var ps = from_box.parentNode.getElementsByTagName('p');
    window.SelectFilter = {  
    7782        var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Added %s') + ' ', [field_name]));
    7883        quickElement('img', title_chosen, '', 'src', admin_media_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of added %s. You may remove some by selecting them below and then clicking the "Remove" button.'), [field_name]));
    7984
    80         var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', from_box.getAttribute('name'));
     85        var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', real_box.attr('name') + '_to');
    8186        to_box.className = 'filtered';
    8287        var clear_all = quickElement('a', selector_chosen, gettext('Remove all'), 'href', 'javascript: (function() { SelectBox.move_all("' + field_id + '_to", "' + field_id + '_from"); SelectFilter.refresh_icons("' + field_id + '");})()', 'id', field_id + '_remove_all_link');
    8388        clear_all.className = 'selector-clearall';
    8489
    85         from_box.setAttribute('name', from_box.getAttribute('name') + '_old');
    86 
    8790        // Set up the JavaScript event handlers for the select box filter interface
    8891        addEvent(filter_input, 'keyup', function(e) { SelectFilter.filter_key_up(e, field_id); });
    8992        addEvent(filter_input, 'keydown', function(e) { SelectFilter.filter_key_down(e, field_id); });
    90         addEvent(from_box, 'change', function(e) { SelectFilter.refresh_icons(field_id) });
    91         addEvent(to_box, 'change', function(e) { SelectFilter.refresh_icons(field_id) });
    92         addEvent(from_box, 'dblclick', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); });
    93         addEvent(to_box, 'dblclick', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); });
     93        addEvent(from_box, 'change', function(e) { SelectFilter.refresh_state(field_id) });
     94        addEvent(to_box, 'change', function(e) { SelectFilter.refresh_state(field_id) });
     95        addEvent(from_box, 'dblclick', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_state(field_id); });
     96        addEvent(to_box, 'dblclick', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_state(field_id); });
    9497        addEvent(findForm(from_box), 'submit', function() { SelectBox.select_all(field_id + '_to'); });
    9598        SelectBox.init(field_id + '_from');
    9699        SelectBox.init(field_id + '_to');
    window.SelectFilter = {  
    103106        }
    104107
    105108        // Initial icon refresh
    106         SelectFilter.refresh_icons(field_id);
     109        SelectFilter.refresh_state(field_id);
    107110    },
    108     refresh_icons: function(field_id) {
     111    refresh_state: function(field_id) {
     112        // Refresh icons
     113        var real = $('#' + field_id);
    109114        var from = $('#' + field_id + '_from');
    110115        var to = $('#' + field_id + '_to');
    111116        var is_from_selected = from.find('option:selected').length > 0;
    window.SelectFilter = {  
    116121        // Active if the corresponding box isn't empty
    117122        $('#' + field_id + '_add_all_link').toggleClass('active', from.find('option').length > 0);
    118123        $('#' + field_id + '_remove_all_link').toggleClass('active', to.find('option').length > 0);
     124
     125        // Refresh selected items
     126        real.find('option').attr('selected', false); // Deselect everything
     127        to.find('option').each(function() {
     128            // Select the same options as the ones present in the 'to' box.
     129            real.find('option[value="' + this.value + '"]').attr('selected', true);
     130        });
    119131    },
    120132    filter_key_up: function(event, field_id) {
    121133        var from = document.getElementById(field_id + '_from');
Back to Top