Ticket #6183: newforms-admin_ManyToManyField-widget.patch

File newforms-admin_ManyToManyField-widget.patch, 3.5 KB (added by Steven Armstrong <sa@…>, 17 years ago)
  • django/db/models/fields/related.py

     
    637637        self.db_table = kwargs.pop('db_table', None)
    638638        Field.__init__(self, **kwargs)
    639639
    640         msg = ugettext_lazy('Hold down "Control", or "Command" on a Mac, to select more than one.')
     640        msg = ugettext_lazy('<span class="select-multiple-help-text">Hold down "Control", or "Command" on a Mac, to select more than one.</span>')
    641641        self.help_text = string_concat(self.help_text, ' ', msg)
    642642
    643643    def get_manipulator_field_objs(self):
  • django/contrib/admin/media/js/SelectFilter2.js

     
    1414    return node;
    1515}
    1616
     17function findSelectMultipleHelpTextNode(node) {
     18    var nodes = node.getElementsByTagName('span');
     19    for (var i=0, length=nodes.length; i<length; i++) {
     20        if (nodes[i].className == 'select-multiple-help-text') {
     21            // assume there's only one
     22            return nodes[i];
     23        }
     24    }
     25    return null;
     26}
     27
     28function findHelpTextNodes(node) {
     29    var nodes = node.getElementsByTagName('p');
     30    var result = [];
     31    for (var i=0, length=nodes.length; i<length; i++) {
     32        if (nodes[i].className == 'help') {
     33            result.push(nodes[i]);
     34        }
     35    }
     36    return result;
     37}
     38
    1739var SelectFilter = {
    1840    init: function(field_id, field_name, is_stacked, admin_media_prefix) {
    1941        var from_box = document.getElementById(field_id);
    2042        from_box.id += '_from'; // change its ID
    2143        from_box.className = 'filtered';
    2244
    23         // Remove <p class="info">, because it just gets in the way.
    24         var ps = from_box.parentNode.getElementsByTagName('p');
    25         for (var i=0; i<ps.length; i++) {
    26             from_box.parentNode.removeChild(ps[i]);
     45        // Find and remove the span tag wich holds the
     46        // 'Hold down "Control", or "Command" on a Mac, to select more than one.'
     47        // message.
     48        var smhelp_node = findSelectMultipleHelpTextNode(from_box.parentNode);
     49        if (smhelp_node) {
     50            smhelp_node.parentNode.removeChild(smhelp_node);
    2751        }
    2852
     53        // Find and remove all user supplied help_text's.
     54        var help_text_nodes = findHelpTextNodes(from_box.parentNode);
     55        var removed_nodes = [];
     56        for (var i=0, length=help_text_nodes.length; i<length; i++) {
     57            removed_nodes.push(help_text_nodes[i].parentNode.removeChild(help_text_nodes[i]));
     58        }
     59
    2960        // <div class="selector"> or <div class="selector stacked">
    3061        var selector_div = quickElement('div', from_box.parentNode);
    3162        selector_div.className = is_stacked ? 'selector stacked' : 'selector';
     
    76107        SelectBox.init(field_id + '_to');
    77108        // Move selected from_box options to to_box
    78109        SelectBox.move(field_id + '_from', field_id + '_to');
     110
     111        // Put the user supplied help_text's back into the dom at a place where they
     112        // don't interfere with the SelectFilter widget.
     113        for (var i=0, length=removed_nodes.length; i<length; i++) {
     114            from_box.parentNode.parentNode.parentNode.appendChild(removed_nodes[i]);
     115        }
    79116    },
    80117    filter_key_up: function(event, field_id) {
    81118        from = document.getElementById(field_id + '_from');
Back to Top