Tuesday, June 28, 2011

widgets js

I am try to do litle widget

class My_widjet(forms.widgets.TextInput):
class Media:
js = (
'js/my_calendar/cal.js',
)
def render(self, name, value, attrs=None):
to_return = u""" %s
<p><input type="text" value="dd-mm-yy"
onfocus="this.select();lcs(this)"onclick="event.cancelBubble=true;this.select();lcs(this)"><input
type="text" value="dd-mm-yy"
onfocus="this.select();lcs(this)"onclick="event.cancelBubble=true;this.select();lcs(this)">
</p></p>
""" %self.media
return mark_safe(to_return)
in "My_Project/js/my_calendar/cal.js" is JavaScript of calendar
then I use My widget

class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField(required=False)
Date = forms.CharField(widget = My_widjet)

In browser i see ...<script type="text/javascript" src="js/my_calendar/
cal.js"></script>...
But calendar is not working :(
if I just make simple html document with
"<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/my_calendar/cal.js"></script>

<p><input type="text" value="dd-mm-yy"
onfocus="this.select();lcs(this)"
onclick="event.cancelBubble=true;this.select();lcs(this)">
ddd<input type="text" value="dd-mm-yy"
onfocus="this.select();lcs(this)"
onclick="event.cancelBubble=true;this.select();lcs(this)">
</p>
</p>
" It works
but in django does non.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment