Hey there, Just trying to get a handle on how forms in nevow work. Reading through it looks like there are two main ways to express forms; as loose properties, and as methods - or: --- class IUser_FormEdit(annotate.TypedInterface): name = annotate.String() age = annotate.Integer() vs class IUser_FormEdit(annotate.TypedInterface): def edit( self, name=annotate.String(), age=annotate.Integer() ): pass annotate.autocallable( edit ) --- Properties make it easy to present the existing values of an object - but as far as I can tell, they're a one per form kind of thing. Methods on the other hand are good since as it's easy to throw a bunch of elements in a single form; but it looks horrible trying to load them up with existing data. The only way I've found is in the pastebin example: --- formDefaults = context.locate(iformless.IFormDefaults) formDefaults.setDefault('editPasting.text', version.getText()) formDefaults.setDefault('editPasting.postedBy', version.getAuthor()) --- Is there a way to show more than one property in a form + have an action triggered when the property update is over? Is there a more intuitive way of loading values into a method defined form than the pastebin example? cheers! Andy.
Andy Gayton wrote:
Reading through it looks like there are two main ways to express forms; as loose properties, and as methods - or:
Properties make it easy to present the existing values of an object - but as far as I can tell, they're a one per form kind of thing. Methods on the other hand are good since as it's easy to throw a bunch of elements in a single form; but it looks horrible trying to load them up with existing data.
The only way I've found is in the pastebin example:
--- formDefaults = context.locate(iformless.IFormDefaults) formDefaults.setDefault('editPasting.text', version.getText()) formDefaults.setDefault('editPasting.postedBy', version.getAuthor()) ---
Is there a more intuitive way of loading values into a method defined form than the pastebin example?
Just chatted with mg on irc - it looks like this sort of thing is necessary - so you do have to have a custom render_ something that pokes defaults into the form. There is some nicer syntax to do it with though: defaults = ctx.locate(IFormDefaults) myForm = defaults.getAllDefaults('nameOfForm') myForm['foo'] = 'bar' and ctx.locate(IFormDefaults).getAllDefaults('nameOfForm').update(aDictWithEverythingIn) Thanks mg! Andy.
participants (1)
-
Andy Gayton