[Grok-dev] Customized grok.AddForm

Sebastian Ware sebastian at urbantalk.se
Thu Jul 30 08:59:53 EDT 2009


30 jul 2009 kl. 14.46 skrev Tim Cook:

>
> I have an add form (below).  The generic one does schema validation as
> expected.  But when I assign a custom template, it does not do schema
> validation.  The setUpWidgets function doesn't work in either case.
>
> I created the custom template by copying the source output from the
> generic (Grok generated) form and then adding some CSS and additional
> text and graphics.   The only thing I  changed in the <form> itself  
> was
> the action in order to point to the view template in my previous email
> about update().
>
> Of course original just calls itself:
>  <form action="http://localhost:8080/dsedemo/immunizationsform"
>      method="post" class="edit-form"
>      enctype="multipart/form-data">
>
> I changed it to:
>
> <form  tal:attributes="action python:view.url('immcalc')"
>      method="post" class="edit-form"
>      enctype="multipart/form-data">
>

   python:view.url('immcalc')

Shouldn't this be:

   python:view.url(context, 'immunizationsform')

or maybe just:

   <form action="immunizationsform"

or:

   <form action=""

>
> So my questions are:
>
> 1. Why no schema  validation in the customized form?

I don't think the post-back is done to the right url.

>
> 2. Why does the setUpWidgets function not work in either case?

You might need to set a breakpoint and investigate. A textarea has  
width/height but a TextLine has displayWidth. Maybe this could be  
tripping you up.

Mvh Sebastian

>
> Thanks,
> Tim
>
> *********************************************************
> class ImmunizationsForm(grok.AddForm):
>    grok.context(dsedemo)
>    form_fields = grok.AutoFields(ImmunizationList)
>
>    #here we setup an alternate display form that has been customized
> from the original generic add form.
>    #the URL though is still to /immunizationsform NOT to immadd.
>    template = grok.PageTemplateFile('dsedemo_templates/immadd.pt')
>
>    def setUpWidgets(self):
>        super(ImmunizationsForm, self).setUpWidgets()
>        self.widgets['hepatitisB'].width = 1
>        self.widgets['tetravalent'].width = 1
>        self.widgets['polio'].width = 1
>        self.widgets['rotavirus'].width = 1
>
>
>
>    @grok.action('Process')
>    def add(self, **data):
>        immlist = ImmunizationList()
>        self.applyData(immlist, **data)
>        self.context[name] = immlist
>        return self.redirect(self.url(self.context[name]))
>
> *******************************************************************
>
> -- 
> Timothy Cook, MSc
> Health Informatics Research & Development Services
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
> Skype ID == timothy.cook
> ***************************************************************
> *You may get my Public GPG key from  popular keyservers or    *
> *from this link http://timothywayne.cook.googlepages.com/home *
> ***************************************************************
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list