This is really great! I have the following question, though: how would
I best use it (in a controller, I assume) so that the list of
available tags were always up-to-date from a table?
For example:
db.define_table('tags',
SQLField('name','string')
)
db.define_table('taggable',
SQLField('somecontent','text'),
SQLField('tags','text)
)
I understand I have to attach the widget with db.taggable.tags.widget
= lambda s,v: tagging_widget(s,v, ***something***)
Can I just say ***something*** is db.(db.tags.id > 0).select('name')
and that would keep it in sync with the contents of the 'tags' table?
Sorry if this is a stupid question... :)
André
On Sep 9, 6:20 am, Massimo Di Pierro <[EMAIL PROTECTED]> wrote:
> DEFINITION:
>
> def tagging_widget(self,value,tags=[]):
> script=SCRIPT("""
> function web2py_tag(self,other,tag) {
> var o=document.getElementById(other)
> if(self.className=='tag_on') {
> self.setAttribute('class','tag_off');
> o.value=o.value.replace('['+tag+']','');
> }
> else if(self.className=='tag_off') {
> self.setAttribute('class','tag_on');
> o.value=o.value+'['+tag+']';
> }
> }
> """)
> id=self._tablename+'_'+self.name
> def onclick(x): return "web2py_tag(this,'%s','%s');"%(id,x.lower())
> buttons=[SPAN(A(x,_class='tag_on' if value and '[%s]'%x.lower() \
> in value else 'tag_off',_onclick=onclick(x)),' ') for x
> in tags]
> return DIV(script,INPUT(_type='hidden',_id=id,_name=self.name,
> _value=value),*buttons)
>
> USAGE:
>
> mytags=[,'Django','TurboGears','Pylons','web2py']
> db.define_table('proposal',SQLField('tags','text'))
> db.proposal.tags.widget=lambda s,v: tagging_widget(s,v,mytags)
> form=SQLFORM(db.proposal)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---