Ticket #9784: 9784.diff

File 9784.diff, 8.7 KB (added by David Gouldin, 15 years ago)
  • django/forms/forms.py

     
    387387            name = self.html_initial_name
    388388        return widget.render(name, data, attrs=attrs)
    389389
     390    def as_widget_js_value(self, widget=None, attrs=None, only_initial=False):
     391        if not widget:
     392            widget = self.field.widget
     393        attrs = attrs or {}
     394        auto_id = self.auto_id
     395        if auto_id and 'id' not in attrs and 'id' not in widget.attrs:
     396            attrs['id'] = auto_id
     397        if not only_initial:
     398            name = self.html_name
     399        else:
     400            name = self.html_initial_name
     401        return widget.js_value(name, attrs=attrs)
     402
    390403    def as_text(self, attrs=None, **kwargs):
    391404        """
    392405        Returns a string of HTML for representing this as an <input type="text">.
  • django/forms/widgets.py

     
    631631            output.append(widget.render(name + '_%s' % i, widget_value, final_attrs))
    632632        return mark_safe(self.format_output(output))
    633633
     634    def js_value(self, name, attrs=None):
     635        widget_values = []
     636        final_attrs = self.build_attrs(attrs)
     637        id_ = final_attrs.get('id', None)
     638        for i, widget in enumerate(self.widgets):
     639            if id_:
     640                widget_id = '%s_%s' % (id_, i)
     641            else:
     642                widget_id = name + '_%s' % i
     643            widget_values.append('document.getElementById("%s").value' % widget_id)
     644        return ' + " " + '.join(widget_values)
     645
    634646    def id_for_label(self, id_):
    635647        # See the comment for RadioSelect.id_for_label()
    636648        if id_:
     
    699711            return [value.date(), value.time().replace(microsecond=0)]
    700712        return [None, None]
    701713
     714    def js_value(self, name, attrs=None):
     715        widget_values = []
     716        final_attrs = self.build_attrs(attrs)
     717        id_ = final_attrs.get('id', None)
     718        for i, widget in enumerate(self.widgets):
     719            if id_:
     720                widget_id = '%s_%s' % (id_, i)
     721            else:
     722                widget_id = name + '_%s' % i
     723            if isinstance(widget, TimeInput):
     724                widget_values.append('document.getElementById("%s").value.replace(/:/g, "-")' % widget_id)
     725            else:
     726                widget_values.append('document.getElementById("%s").value' % widget_id)
     727        return ' + " " + '.join(widget_values)
     728
    702729class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
    703730    """
    704731    A Widget that splits datetime input into two <input type="hidden"> inputs.
  • django/contrib/admin/media/js/core.js

     
    2929    }
    3030}
    3131
     32function fireEvent(obj, evType) {
     33    if(document.createEvent) {
     34        var evObj = document.createEvent('HTMLEvents');
     35        evObj.initEvent(evType, true, false);
     36        obj.dispatchEvent(evObj);
     37    }
     38    else if(document.createEventObject) {
     39        obj.fireEvent('on' + evType);
     40    }
     41}
     42
    3243// quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]);
    3344function quickElement() {
    3445    var obj = document.createElement(arguments[0]);
  • django/contrib/admin/media/js/admin/DateTimeShortcuts.js

     
    116116       window.document.onclick = null;
    117117    },
    118118    handleClockQuicklink: function(num, val) {
    119        DateTimeShortcuts.clockInputs[num].value = val;
    120        DateTimeShortcuts.dismissClock(num);
     119        var elem = DateTimeShortcuts.clockInputs[num];
     120        elem.value = val;
     121        fireEvent(elem, 'keyup');
     122        DateTimeShortcuts.dismissClock(num);
    121123    },
    122124    // Add calendar widget to a given field.
    123125    addCalendar: function(inp) {
     
    237239        DateTimeShortcuts.calendars[num].drawNextMonth();
    238240    },
    239241    handleCalendarCallback: function(num) {
    240         return "function(y, m, d) { DateTimeShortcuts.calendarInputs["+num+"].value = y+'-'+(m<10?'0':'')+m+'-'+(d<10?'0':'')+d; document.getElementById(DateTimeShortcuts.calendarDivName1+"+num+").style.display='none';}";
     242        return "function(y, m, d) { var elem = DateTimeShortcuts.calendarInputs[" + num + "]; elem.value = y+'-'+(m<10?'0':'')+m+'-'+(d<10?'0':'')+d; document.getElementById(DateTimeShortcuts.calendarDivName1+" + num + ").style.display='none'; fireEvent(elem, 'keyup');}";
    241243    },
    242244    handleCalendarQuickLink: function(num, offset) {
    243245       var d = new Date();
    244        d.setDate(d.getDate() + offset)
    245        DateTimeShortcuts.calendarInputs[num].value = d.getISODate();
     246       d.setDate(d.getDate() + offset);
     247       var elem = DateTimeShortcuts.calendarInputs[num];
     248       elem.value = d.getISODate();
     249       fireEvent(elem, 'keyup');
    246250       DateTimeShortcuts.dismissCalendar(num);
    247251    },
    248252    cancelEventPropagation: function(e) {
  • django/contrib/admin/widgets.py

     
    7070        return mark_safe(u'<p class="datetime">%s %s<br />%s %s</p>' % \
    7171            (_('Date:'), rendered_widgets[0], _('Time:'), rendered_widgets[1]))
    7272
     73    def js_value(self, name, attrs=None):
     74        widget_values = []
     75        final_attrs = self.build_attrs(attrs)
     76        id_ = final_attrs.get('id', None)
     77        for i, widget in enumerate(self.widgets):
     78            if id_:
     79                widget_id = '%s_%s' % (id_, i)
     80            else:
     81                widget_id = name + '_%s' % i
     82            if isinstance(widget, AdminTimeWidget):
     83                widget_values.append('document.getElementById("%s").value.replace(/:/g, "-")' % widget_id)
     84            else:
     85                widget_values.append('document.getElementById("%s").value' % widget_id)
     86        return ' + " " + '.join(widget_values)
     87
    7388class AdminRadioFieldRenderer(RadioFieldRenderer):
    7489    def render(self):
    7590        """Outputs a <ul> for this set of radio fields."""
  • django/contrib/admin/templates/admin/prepopulated_fields_js.html

     
     1{% autoescape off %}
    12<script type="text/javascript">
    23{% for field in prepopulated_fields %}
    34    document.getElementById("{{ field.field.auto_id }}").onchange = function() { this._changed = true; };
     
    23    {% for dependency in field.dependencies %}
    3     document.getElementById("{{ dependency.auto_id }}").onkeyup = function() {
    4         var e = document.getElementById("{{ field.field.auto_id }}");
    5         if (!e._changed) { e.value = URLify({% for innerdep in field.dependencies %}document.getElementById("{{ innerdep.auto_id }}").value{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length|default_if_none:"50" }}); }
    6     }
     4        {% if dependency.field.widget.widgets %}
     5            {% comment %} widget is a MultiWidget {% endcomment %}
     6            {% for widget in dependency.field.widget.widgets %}
     7                document.getElementById("{{ dependency.auto_id }}_{{ forloop.counter0 }}").onkeyup = function() {
     8                    var e = document.getElementById("{{ field.field.auto_id }}");
     9                    if (!e._changed) {
     10                        e.value = URLify({% for innerdep in field.dependencies %}{{ innerdep.as_widget_js_value }}{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length|default_if_none:"50" }});
     11                    }
     12                }
     13            {% endfor %}
     14        {% else %}
     15            document.getElementById("{{ dependency.auto_id }}").onkeyup = function() {
     16                var e = document.getElementById("{{ field.field.auto_id }}");
     17                if (!e._changed) {
     18                    e.value = URLify({% for innerdep in field.dependencies %}document.getElementById("{{ innerdep.auto_id }}").value{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length|default_if_none:"50" }});
     19                }
     20            }
     21        {% endif %}
    722    {% endfor %}
    823{% endfor %}
    924</script>
     25{% endautoescape %}
     26 No newline at end of file
Back to Top