[Webware] FormKit - dynamic fields problem

J

JZ

I use Webware and FormKit. I have a problem with dynamic added field
to the form. The following code creates one input field and two submit
buttons. I would like to add more (up to 4) input fields after
pressing "more" button. It does not work and I have no idea how to
solve it.

import re
from WebKit.Page import Page
from FormKit import Form, Fields, Validators
from FormKit.FormKitMixIn import FormKitMixIn

class DynamicProblem(FormKitMixIn, Page):

def __init__(self):
Page.__init__(self)
notEmpty = Validators.NotEmpty()
f = self.form = Form.Form()
self.addForm(f)
f.addField(Fields.TextField('msg', validators=[notEmpty]))
f.addField(Fields.WebKitSubmitButton('more'))
f.addField(Fields.WebKitSubmitButton('send'))

def sleep(self, trans):
self.resetForms()
Page.sleep(self, trans)

def writeHTML(self):
self.write(self.form.dump())

def extendForm(self):
notEmpty = Validators.NotEmpty()
f = self.form
nr = len(filter(lambda x:re.match(r'^msg',x),
self.form.values().keys()))
if nr < 4:
f.addField(Fields.TextField('msg%d' % nr,
validators=[notEmpty]))

def actions(self):
return ['more', 'send']

def more(self):
if self.form.isSuccessful():
self.extendForm()

def send(self):
if self.form.isSuccessful():
pass
 
J

Joe Francia

JZ said:
I use Webware and FormKit. I have a problem with dynamic added field
to the form. The following code creates one input field and two submit
buttons. I would like to add more (up to 4) input fields after
pressing "more" button. It does not work and I have no idea how to
solve it.

You also may want to post this question to the WebWare list, if you
haven't already:
http://lists.sourceforge.net/lists/listinfo/webware-discuss

If you don't want to join yet another mailing lists, you can access the
WebWare list in your newsreader by pointing it to news.gmane.org and
subscribing to gmane.comp.python.webware.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top