Massimo, I don't believe! The solution is simpler than I thought. :-)
Thanks a lot! :-)

>From what I read in the manual I thought I had to extend SQLFORM
manually.

The solution solved my needs, but just to clarify me, how I could
implement the same solution but using a class that extends SQLFORM?

On Oct 5, 10:31 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I do not think you need to extend SQLFORM to implement this. You just
> need a new widget for the reference field. I think.
> Not that there is anything worng with extending SQLFORM but I think it
> may be more complex that needs to be.
>
> On Oct 5, 8:22 pm, Renato-ES-Brazil <caliari.ren...@gmail.com> wrote:
>
> > I've created a simple code.
>
> > In my db_task.py I have the following lines, among others:
>
> > from applications.myapp.modules.mywidgets import *
>
> > db.main.product.requires=IS_IN_DB(db,db.product.id,db.product.name,
> > orderby=~db.product.name)
> > db.main.product.widget = options_with_add_link.widget
>
> > And in my module mywidgets.py I have the class:
>
> > class options_with_add_link(SQLFORM):
> >     @staticmethod
> >     def widget(field,value,**attr):
> >         select = OptionsWidget.widget(field,value,**attr)
> >         id = "%(tablename)s_%(fieldname)s" %
> > {"tablename":field._tablename,"fieldname":field.name}
> >         script_add_button = SCRIPT(
> >             """$(document).ready(function() {
> >                 $("#%(id)s").after(
> >                 \"<a target='_blank' href=\'%(url)s\'>%(text)s</a>\"
> >                 );
> >             }
> >             )""" % {"id" : id,"url":URL
> > (a="myapp",c=field.name,f="create"),"text":"Add"}
> >         )
> >         return DIV(select, script_add_button)
>
> > Notice above, in the line where I create the "add" link, that I call
> > the "URL" method by passing hard coded values. I don't want it.
>
> > On Oct 5, 9:44 pm, Renato-ES-Brazil <caliari.ren...@gmail.com> wrote:
>
> > > I am here trying to create a custom widget, inside a class that
> > > extends SQLFORM, but how could I create a custom widget that allow me
> > > to send others parameters besides "field" and "value"?
>
> > > I would like call the new widget by sending the parameters "control"
> > > and "function". So, inside the function, I would use the values to
> > > create properly the "add" link (url).
>
> > > I found only a few examples of customization of widget.
>
> > > Thanks.
>
> > > On Oct 5, 8:03 am, Renato-ES-Brazil <caliari.ren...@gmail.com> wrote:
>
> > > > Cool!
>
> > > > Before I try to do something I really wanted to know if there was
> > > > something done by passing a parameter.
>
> > > > Thanks a lot guys!
>
> > > > On Oct 5, 1:08 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > It would be nice to a widget that does this.
>
> > > > > On Oct 4, 10:14 pm, Álvaro Justen [Turicas] <alvarojus...@gmail.com>
> > > > > wrote:
>
> > > > > > On Sat, Oct 3, 2009 at 02:52, Iceberg <iceb...@21cn.com> wrote:
>
> > > > > > > On Oct3, 8:41am, Renato-ES-Brazil <caliari.ren...@gmail.com> 
> > > > > > > wrote:
> > > > > > >> Hi guys!
>
> > > > > > >> When the form displays the select with several options from the 
> > > > > > >> other
> > > > > > >> table, using the "is_in_db" configuration, couldn't also to put a
> > > > > > >> button, for example "ADD NOW", next to it to allows add a new 
> > > > > > >> option?
>
> > > > > > >> Currently is there this possibility for the CRUD (create and 
> > > > > > >> update
> > > > > > >> forms)?
>
> > > > > > > I've been in same situation as you mentioned. Here is my journey.
>
> > > > > > > Adding a "Add Now" button is easy. You can either customize the 
> > > > > > > form,
> > > > > > > or customize the widget, or just use some jquery effect in a way 
> > > > > > > like
> > > > > > > this:
>
> > > > > > >  def youraction():
> > > > > > >    form=crud.create(...)
> > > > > > >    ...
> > > > > > >    return dict(form=DIV(
> > > > > > >      form,
> > > > > > >      SCRIPT('''$(document).ready(function() {
> > > > > > >      $("#your_widgit_id").after(
> > > > > > >        "<a target='_blank' href='/yourapp/default/addnow'>Add 
> > > > > > > Now</
> > > > > > > a>");
> > > > > > >      });'''),
> > > > > > >      ))
>
> > > > > > > However, I found that after successfully adding a new entry into 
> > > > > > > db,
> > > > > > > there is no obvious way to refresh the is_in_db field itself,
> > > > > > > providing that I don't want to HARDCODE one more dedicated ajax 
> > > > > > > action
> > > > > > > in my already-too-complex controller.
>
> > > > > > > So, my user still have to refresh the whole original page to see 
> > > > > > > the
> > > > > > > change after "add now", with a price of losing all his previous 
> > > > > > > input.
> > > > > > > Lucky enough that I could arrange the is_in_db field at the first 
> > > > > > > line
> > > > > > > of my form, so the waste of input is minimum. In this case, the
> > > > > > > benefit of "Add Now" button is not as big as we thought.
>
> > > > > > > If anybody knows a better solution, please give me some tips. 
> > > > > > > Thanks!
>
> > > > > > You could open a popup with a SQLFORM to create a new register in
> > > > > > other table, with a JavaScript/AJAX to update dropdown's options 
> > > > > > (and
> > > > > > select option that was created), like Djando admin do.
> > > > > > You could also use a "overlay" to show the form instead of the 
> > > > > > popup.
> > > > > > See:http://alvarojunior.com/jquery/joverlay/0.7.1/
>
> > > > > > --
> > > > > >  Álvaro Justen
> > > > > >  Peta5 - Telecomunicações e Software Livre
> > > > > >  21 3021-6001 / 9898-0141
> > > > > >  http://www.peta5.com.br/
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to