You are sticking the form in a servlet instance and then modifiying that form, there is no assurance that the same user will get the same servlet. This will cause lots of bugs that are hard to find.

Any data that needs to be used by the same user should be kept in the session. Stick the form in the session, and move the form creation to awake ( so that a new form is created for each user)

Try this, a different strange behavior, but it will get you on track:

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

class test(FormKitMixIn, Page):
def __init__(self):
Page.__init__(self)


def awake(self,trans):
notEmpty = Validators.NotEmpty()
Page.awake(self,trans)
f = self.session().value('form',None)
if not f:
f = Form.Form()
f.addField(Fields.TextField('msg', validators=[notEmpty]))
f.addField(Fields.WebKitSubmitButton('more'))
f.addField(Fields.WebKitSubmitButton('send'))
self.form = f
self.addForm(f)


   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]))
self.session().setValue('form',f)
def actions(self):
return ['more', 'send']


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

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

JZ wrote:

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





-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss





------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html _______________________________________________ Webware-discuss mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to