[Kss-devel] Problems with kssSubmitForm , changing value of all "input"-tags after select:change?

Balazs Ree ree at ree.hu
Tue Jun 5 07:58:40 CEST 2007


On Mon, 04 Jun 2007 21:41:29 +0200 Nylan-hi6Y0CQ0nG0 wrote:

> I'm having some problems with kssSubmitForm, but the demo works without
> problems.
> 
> Use-case:
> There is one "select"-tag in forms.pt with a vocabulary based choice
> (data fetched from database) On "select:change" I would like to change
> the attribute "value" of all "input"-tags as well.(value fetched again
> from sql database) My aim is to initialise input tags with data from
> templates("select"-Tag)
> 
> 
> So my first idea was kssSubmitForm (dictionary of all input fields)  -->
> doesn't work at all (see below) and to use setAttribute somehow.  :-)

To debug this sort of problem, first you would look at what is actually 
sent up to the server. This can be done by capturing the traffic between 
the client and the server (by tcpwatch), or simply looking at the request 
in FireBug and see what actually has sent up.

p.s. if you are on FireFox, do not call createLogginPane, but use 
FireBug. It is much more friendly.

Doing so you would realize that the client sends up what's expected, so 
the submit works correctly, however the error happens on the server side. 
Also the error message indicates the publisher has problems marshalling 
the form to the variables. So the signature of the method is wrong 
somehow. We will soon see why.


---------------------------------------------------------------------------------------------------------------
> select:change {
>         action-server: submitFullForm;
>         submitFullForm-kssSubmitForm: 'source';
> }
> 
---------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------
> from kss.core import KSSView ,kssaction from datetime import datetime
> 
> class DemoView(KSSView):
> 
>     @kssaction
>     def submitFullForm(self, form):
>         assert hasattr(form, 'keys'), 'Form data is expected to be a
>         dict-like object.' # marshall back the repr of this dict.
>         ksscore = self.getCommandSet('core')
>         ksscore.replaceInnerHTML('#target', repr(form))
> 
---------------------------------------------------------------------------------------------------------------

So the problem is that kssSubmitForm works differently then sending up 
individual parameters: it sends up the form values to the request 
directly. This means the variables you receive are the variables that 
would be sent up if you did an ordinary form submit in the normal way.

On the server you have two main options (similarly to the ordinary 
submits withoug kss): 
- do not specify parameters in the method, and access your field 
variables from REQUEST, or: 
- specify parameters on the method (not "form" but the actual field 
names), and let the publisher marshall them automatically, but then they 
must exist on the form otherwise you get an error. 

so in the end the solution is to try:

     @kssaction
     def submitFullForm(self, keys):
         ...

I hope this helps you to continue.

Also Godefroid's advice will turn out to be very useful, wherever 
possible, try to reuse the things you render on the server for 
replacement in the page, instead of tweaking attributes manually. This is 
however not a rule, just a useful pattern.

-- 
Balazs Ree



More information about the Kss-devel mailing list