Hi guys!
I working on some new fields to FunFormKit, it is a specific case.
I want to make a AdressField that aggregate street, number, extra information and postal code in only one widget. These is not a problem, I already done the presentation and validation to this Field, the problem is that, when some internal field are invalid, the whole field data are lost. See my code, the top struct Address contains a street, a number, an extra and a zip code (this zip code is called cep in Brazil, the cep has only 8 digits, so I check it).
...
class AddressField(Field):
def __init__(self, name, validators=None, **kw):
Field.__init__(self, name, validators=validators, **kw)
def htInput(self, default, options, nameMap=identity):
return html.table(
html.tr(
html.td('Street:'),
html.td(html.input.text(name=nameMap(self.name()+':street'), size=100)),
html.td('Number:'),
html.td(html.input.text(name=nameMap(self.name()+':number'), size=10)),
),
html.tr(
html.td('Extra:'),
html.td(html.input.text(name=nameMap(self.name()+':extra'), size=100)),
html.td('ZIP:'),
html.td(html.input.text(name=nameMap(self.name()+':zip'), size=10)),
),
)
def htHidden(self, default, options, nameMap=identity): return Field.htHidden(self, default, options, nameMap=nameMap)
def unvalidatedValueFromFields(self, fields, nameMap=identity):
d={}
d['street']=fields.get(nameMap(self.name()+':street'))
d['number']=fields.get(nameMap(self.name()+':number'))
d['extra']=fields.get(nameMap(self.name()+':extra'))
d['zip']=fields.get(nameMap(self.name()+':zip'))
return d
def valueFromFields(self, fields, nameMap=identity):
d=self.unvalidatedValueFromFields(fields, nameMap)
tmp=''
for c in d['zip']:
if c in string.digits:
tmp+=c
d['zip']=tmp
if d['zip'] and len(d['zip'])<8:
raise Validator.InvalidField, 'The zip code is invalid!'
return d
...I done another widget, this widget without sucess. I try to make an button box containing 2 buttons, OK and Cancel. The OK button should call on_ok_clicked and the Cancel button should call on_cancel_clicked, the Cancel button should suppress validation too. I try this way:
...
class OKCancelButtonField(Field):
def __init__(self, name, methodToInvoke=None, invokeAsFunction=False,
noneAsDefault = False, suppressValidation = False, confirm=None, defaultSubmit=False, **kw):
Field.__init__(self, name, validators = [], **kw)
self.ok=SubmitButton('ok', description='OK', methodToInvoke='on_ok_clicked')
self.cancel=SubmitButton('cancel', description='Cancel', methodToInvoke='on_cancel_clicked', suppressValidation=True)
def htInput(self, default, options, nameMap=identity):
return html.p(
self.ok.htInput(default, options, nameMap),
self.cancel.htInput(default, options, nameMap),
)
def valueFromFields(self, fields, nameMap=identity): self.ok.valueFromFields(fields, nameMap=identity) self.cancel.valueFromFields(fields, nameMap=identity) return True ...
I try making some another methods call the ok and cancel methods (like attemptConvert), without sucess. Can I do this button box the way I want? What should I do, is there a guide on how to write my own fields?
There is a problem with the layout syntax too, if I try to use something like:
layout=[ ':field1', '=some text', ['=some another text', ':field2'], ]
The first 2 lines should work as expected, but the last one not, I get an error telling me that '=' or ':' cannot be in the field name.
Thanks for the attention and sorry to post questions about FunFormKit in Webware list, but I think FunFormKit don't have a list.
------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php _______________________________________________ Webware-discuss mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/webware-discuss
