See how the first render fails to populate a value. Am I doing
something wrong? I've using version 1.2.1.
Are there any good examples out there? Chapter 6 of the 1.1 book
covers some of this but it's not complete (it also has a bug unless
I'm missing something - "person" and "people" are used
inconsistently).
Yeah as far as I know it does not work like that for the first case.
You need to preprocess your defaults with
formencode.variabledecode.variable_encode() to change the first case
into the second case.
I'm still working on a good repetitions example, are you using
javascript? You should look at formencode's NestedVariables,
variable_encode and variable_decode to start.
On Mon, Nov 2, 2009 at 11:21 AM, Mike Burrows (asplake)
> See how the first render fails to populate a value. Am I doing
> something wrong? I've using version 1.2.1.
> Are there any good examples out there? Chapter 6 of the 1.1 book
> covers some of this but it's not complete (it also has a bug unless
> I'm missing something - "person" and "people" are used
> inconsistently).
On Nov 2, 8:32 pm, Ian Wilson <vengfulsquir...@gmail.com> wrote:
> Yeah as far as I know it does not work like that for the first case.
> You need to preprocess your defaults with
> formencode.variabledecode.variable_encode() to change the first case
> into the second case.
Thanks Ian, I'll look into that tomorrow.
> I'm still working on a good repetitions example, are you using
> javascript? You should look at formencode's NestedVariables,
> variable_encode and variable_decode to start.
I did plan to use Javascript, then I took a closer look at the 1.1
book and thought I'd see how I would get on with the approach outlined
there. After struggling a little I decided to play it safe and not
add rows dynamically (by either method) to start with. Either way,
the need to populate the form with data remains.
I have NestedVariables and ForEach in my parent form schema, but (in
my code at least) they don't come into play until validation time.
Anyway, I hope to understand this a bit better after following your
first piece of advice.
A really solid good example of this would brilliant. Forms in Pylons
do take a bit of getting used to (which is about the worst I can say
about what has been a positive experience for the most part)!
Makes one wonder why this (and NestedVariables) can't be there by
default though - it would make for a much smaller gap between the
easy, documented examples and the real world! All it would take is an
enanced render method and perhaps a subclass of Schema. Or perhaps
this goes on a list of recommended things to go in base.py (or
similar)?
For the record, my little example now looks like this:
import formencode.htmlfill as htmlfill
from formencode.variabledecode import variable_encode
Thanks for posting this. How have you solved the problem of
recreating the repeated fields on form validation error? For example,
I'm adding repeated fields via javascript, then we the form POST
occurs and validation fails, I need to figure out how to recreate
those fields in the form. The pylons book example, does solve the
problem, but it sure seems like a lot of code to write for every form
that has a nested structure.
Has anybody got an elegant solution for recreating javascript-added
repeat fields when the form is invalid?
The path I'm heading down is to just use ajax to submit the form.
This keeps the form intact. But now, I have to fill in the error
messages via javascript. Something like,
1. Initial GET, use htmlfill to fill in defaults or model obj values
2. User adds extra repeatable fields via javascript, then submits via
jquery.form plugin
3. Form validation fails, controller returns the formencode error dict
as JSON
4. Javascript will fill in the error messages on the fields
This works reasonably well, but I'm just wondering if anybody has a
better solution.
Regards,
Chris
On Nov 5, 6:38 am, "Mike Burrows (asplake)" <m...@asplake.co.uk>
wrote:
Having got stuck with the basics of populating and validating the
form, I haven't got round to adding rows (dynamically or otherwise).
I think I've got my head sufficiently around the book example to
implement it now but I may yet decide to take the Javascript option.
Meanwhile, I just ensure that there are more enough rows displayed.
Yes the book example is a lot of code (in particular that's a lot of
logic for one action method) but maybe it can be turned into something
reusable. Fantastic if it could...
Regards,
Mike
On Nov 5, 4:07 pm, Chris <fractalbynat...@gmail.com> wrote:
> Thanks for posting this. How have you solved the problem of
> recreating the repeated fields on form validation error? For example,
> I'm adding repeated fields via javascript, then we the form POST
> occurs and validation fails, I need to figure out how to recreate
> those fields in the form. The pylons book example, does solve the
> problem, but it sure seems like a lot of code to write for every form
> that has a nested structure.
> Has anybody got an elegant solution for recreating javascript-added
> repeat fields when the form is invalid?
> The path I'm heading down is to just use ajax to submit the form.
> This keeps the form intact. But now, I have to fill in the error
> messages via javascript. Something like,
> 1. Initial GET, use htmlfill to fill in defaults or model obj values
> 2. User adds extra repeatable fields via javascript, then submits via
> jquery.form plugin
> 3. Form validation fails, controller returns the formencode error dict
> as JSON
> 4. Javascript will fill in the error messages on the fields
> This works reasonably well, but I'm just wondering if anybody has a
> better solution.
> Regards,
> Chris
> On Nov 5, 6:38 am, "Mike Burrows (asplake)" <m...@asplake.co.uk>
> wrote: