I'm trying to subclass the Select widget, so that I can create an editable scrolling list (done via JavaScript code that I found).
My entire class is as follows: --Code-- from django import forms class ComboBox(forms.Select): class Media: js = ("/js/wise/comboBox.js",) def __init__(self, choices=()): # Set up calls to the combo box JavaScript attrs = { "onFocus": "return combo_focus(this);", "onChange": "return combo_change(this);", "onKeyDown": "return combo_keydown(this, event);", "onKeyPress": "return combo_keypress(this, event);", "onKeyUp": "return combo_keyup(this, event);", "onClick": "return combo_click(this, '');" } super(ComboBox, self).__init__(attrs, choices) --Code-- The form that uses it looks like: --Code-- class TestTargetForm(forms.Form): # Family name fname = forms.ModelChoiceField( queryset=TargetFamily.objects.all(), required = False, label = "Family Name", empty_label = "[Match All]", widget = ComboBox ) --Code-- Issue #1: I figured out that I can add HTML attributes by setting the 'attrs' variable. Which means I only need to create __init__() and not render(). That works fine except that I want to call a JavaScript function with a string (the onClick attribute). The single quotes get escaped. How would you pass a string to a JavaScript function using 'attrs'? Issue #2: The 'class Media' definition is being ignored when running through the Django server. I can import my class in python, instantiate the class, and print the media: python manage.py shell >>> from share.widgets import ComboBox >>> print ComboBox().media <script type="text/javascript" src="/js/wise/comboBox.js"></script> but when I look at the web page source coming back from the Django server, that <script></script> text isn't there. Did I need to do anything else? I would appreciate any help either by example or pointers to examples or docs. I looked in the Django source and it looks like the admin stuff sets Media just like I'm doing. The Django doc page for Media also shows an example that looks just like what I'm doing (doesn't mention that I have to do anything else). -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---