Ticket #9784: 9784.diff
File 9784.diff, 8.7 KB (added by , 16 years ago) |
---|
-
django/forms/forms.py
387 387 name = self.html_initial_name 388 388 return widget.render(name, data, attrs=attrs) 389 389 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 390 403 def as_text(self, attrs=None, **kwargs): 391 404 """ 392 405 Returns a string of HTML for representing this as an <input type="text">. -
django/forms/widgets.py
631 631 output.append(widget.render(name + '_%s' % i, widget_value, final_attrs)) 632 632 return mark_safe(self.format_output(output)) 633 633 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 634 646 def id_for_label(self, id_): 635 647 # See the comment for RadioSelect.id_for_label() 636 648 if id_: … … 699 711 return [value.date(), value.time().replace(microsecond=0)] 700 712 return [None, None] 701 713 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 702 729 class SplitHiddenDateTimeWidget(SplitDateTimeWidget): 703 730 """ 704 731 A Widget that splits datetime input into two <input type="hidden"> inputs. -
django/contrib/admin/media/js/core.js
29 29 } 30 30 } 31 31 32 function 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 32 43 // quickElement(tagType, parentReference, textInChildNode, [, attribute, attributeValue ...]); 33 44 function quickElement() { 34 45 var obj = document.createElement(arguments[0]); -
django/contrib/admin/media/js/admin/DateTimeShortcuts.js
116 116 window.document.onclick = null; 117 117 }, 118 118 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); 121 123 }, 122 124 // Add calendar widget to a given field. 123 125 addCalendar: function(inp) { … … 237 239 DateTimeShortcuts.calendars[num].drawNextMonth(); 238 240 }, 239 241 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');}"; 241 243 }, 242 244 handleCalendarQuickLink: function(num, offset) { 243 245 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'); 246 250 DateTimeShortcuts.dismissCalendar(num); 247 251 }, 248 252 cancelEventPropagation: function(e) { -
django/contrib/admin/widgets.py
70 70 return mark_safe(u'<p class="datetime">%s %s<br />%s %s</p>' % \ 71 71 (_('Date:'), rendered_widgets[0], _('Time:'), rendered_widgets[1])) 72 72 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 73 88 class AdminRadioFieldRenderer(RadioFieldRenderer): 74 89 def render(self): 75 90 """Outputs a <ul> for this set of radio fields.""" -
django/contrib/admin/templates/admin/prepopulated_fields_js.html
1 {% autoescape off %} 1 2 <script type="text/javascript"> 2 3 {% for field in prepopulated_fields %} 3 4 document.getElementById("{{ field.field.auto_id }}").onchange = function() { this._changed = true; }; … … 2 3 {% 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 %} 7 22 {% endfor %} 8 23 {% endfor %} 9 24 </script> 25 {% endautoescape %} 26 No newline at end of file