Le 23/10/2008 10:03, Sanjay a écrit : >> is it for tg ot tw widgets ? >> > > It is for tg widgets. > > >> For tg widgets I did something in one of my projects. It is not packaged >> as an egg or module but I think I can extract the relevant parts... >> It can handle (I hope) any compound widget, even if some field is >> handled by a JS script. >> >> Just let me know if you are interested. >> > > I am quite interested. Thanks a lot! Specifically, I am looking for > how I can repeat AutoCompleteFields. > > Here is an example (I cut & paste some parts of my own code, I hope I don't forgot to many parts :-) )
class AutoRepeatFieldHoriz(widgets.RepeatingFormField):
params = ['libelle_add', 'libelle_remove', 'allow_delete_all', 'table']
libelle_add = None
libelle_remove = None
allow_delete_all = False
template = """
<div xmlns:py="http://purl.org/kid/ns#" py:strip="True">
<script py:if="libelle_add or libelle_remove"
language="JavaScript" type="text/javascript">
AutoRepeat_${field_id} = new AutoRepeat('${field_id}',
${int(allow_delete_all)});
MochiKit.DOM.addLoadEvent(AutoRepeat_${field_id}.initialize);
</script>
<span py:for="repetition in repetitions"
id="${field_id}_${repetition}">
${display_field_for(fields[0])}<a
href="javascript:AutoRepeat_${field_id}.removeItem('${field_id}_${repetition}');"><img
src="/static/images/croix-rouge.gif" border="0" title="${libelle_remove}"
alt="${libelle_remove}" /></a></span>
<span py:if="libelle_add" id="${field_id}_ref"
next_index="${next_index}" class="add_field"><a
href="javascript:AutoRepeat_${field_id}.addItem();"><img
src="/static/images/croix-verte.gif" border="0" title="${libelle_add}"
alt="${libelle_add}" /></a></span>
</div>
"""
def __init__(self, *args, **kw):
super(AutoRepeatFieldHoriz, self).__init__(*args, **kw)
if (self.libelle_add) or (self.libelle_remove):
self.javascript = [JSSource("MochiKit = {__export__: false};
", name="MochiKit_param"),
mochikit,
JSLink(my_static,
'javascript/auto_repeat.js'), ]
def display(self, value=None, **params):
if value and isinstance(value, list) and len(value) > 0:
params['repetitions'] = len(value)
params['next_index'] = params.get('repetitions', self.repetitions)
return super(AutoRepeatFieldHoriz, self).display(value, **params)
# some fields with one that uses the AutoRepeatField feature
class FiltreAnnoncesFields(widgets.WidgetsList):
prix = TextField(validator=validators.Int(), attrs={'size':3},
field_class='champ_filtre')
cp = AutoRepeatFieldHoriz(fields=[TextField('cp',
validator=IsCodePostal(),
attrs={'size':5,
'maxlength':5}, field_class='champ_filtre')],
libelle_add=u"Ajouter un code postal",
libelle_remove=u"Supprimer ce code postal")
The JS part is based on MochiKit, and attached you'll find some useful
files...
I don't know if it will work with AutoCompleteField but I've already
used it with custom fields with JS embedded...
> Sanjay
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---
auto_repeat.js
Description: JavaScript source
<<inline: croix-rouge.gif>>
<<inline: croix-verte.gif>>

