kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Insert chooser widget telepath definition onto template
							rodzic
							
								
									49c2c70a22
								
							
						
					
					
						commit
						a7318bf70b
					
				|  | @ -1,5 +1,7 @@ | |||
| from django.core.exceptions import ImproperlyConfigured | ||||
| 
 | ||||
| from wagtail.telepath import JSContext | ||||
| 
 | ||||
| from .inline_panel import InlinePanel | ||||
| 
 | ||||
| 
 | ||||
|  | @ -26,8 +28,19 @@ class MultipleChooserPanel(InlinePanel): | |||
|             self.chooser_widget = self.formset.empty_form.fields[ | ||||
|                 self.panel.chooser_field_name | ||||
|             ].widget | ||||
|             self.js_context = JSContext() | ||||
|             self.chooser_widget_telepath_definition = self.js_context.pack( | ||||
|                 self.chooser_widget | ||||
|             ) | ||||
| 
 | ||||
|         def get_context_data(self, parent_context=None): | ||||
|             context = super().get_context_data(parent_context) | ||||
|             context["chooser_field_name"] = self.panel.chooser_field_name | ||||
|             context[ | ||||
|                 "chooser_widget_definition" | ||||
|             ] = self.chooser_widget_telepath_definition | ||||
|             return context | ||||
| 
 | ||||
|         @property | ||||
|         def media(self): | ||||
|             return super().media + self.js_context.media | ||||
|  |  | |||
|  | @ -8,6 +8,10 @@ | |||
| {% endblock %} | ||||
| 
 | ||||
| {% block js_init %} | ||||
|     {% with script_id="id_"|add:self.formset.prefix|add:"-CHOOSER_WIDGET" %} | ||||
|         {{ chooser_widget_definition|json_script:script_id }} | ||||
|     {% endwith %} | ||||
| 
 | ||||
|     <script> | ||||
|         (function() { | ||||
|             var panel = new InlinePanel({ | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Matt Westcott
						Matt Westcott