Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Repeating elements and htmlfill
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Mike Burrows (asplake)  
View profile   Translate to Translated (View Original)
 More options 2 Nov, 19:21
From: "Mike Burrows (asplake)" <m...@asplake.co.uk>
Date: Mon, 2 Nov 2009 11:21:01 -0800 (PST)
Local: Mon 2 Nov 2009 19:21
Subject: Repeating elements and htmlfill
Hi,

htmlfill.render() doesn't seem to handle repeating elements as I
expect.  I've boiled my code down to this example:

    import formencode.htmlfill as htmlfill
    template = '<input id="weightings-0.weight"
name="weightings-0.weight" type="text" value="" />'
    print htmlfill.render(template, defaults={'weightings':
[{'weight': 1.0}]})
    print htmlfill.render(template, defaults={'weightings-0.weight':
1.0})

Output:

    <input id="weightings-0.weight" name="weightings-0.weight"
type="text" value=""/>
    <input id="weightings-0.weight" name="weightings-0.weight"
type="text" value="1.0" />

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).

Thanks,

Mike
m...@asplake.co.uk
http://positiveincline.com
http://twitter.com/asplake


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Wilson  
View profile   Translate to Translated (View Original)
 More options 2 Nov, 20:32
From: Ian Wilson <vengfulsquir...@gmail.com>
Date: Mon, 2 Nov 2009 12:32:47 -0800
Local: Mon 2 Nov 2009 20:32
Subject: Re: Repeating elements and htmlfill
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)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Burrows (asplake)  
View profile   Translate to Translated (View Original)
 More options 2 Nov, 21:12
From: "Mike Burrows (asplake)" <m...@asplake.co.uk>
Date: Mon, 2 Nov 2009 13:12:09 -0800 (PST)
Local: Mon 2 Nov 2009 21:12
Subject: Re: Repeating elements and htmlfill

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)!

Thanks & regards,
Mike


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Burrows (asplake)  
View profile   Translate to Translated (View Original)
 More options 3 Nov, 09:46
From: "Mike Burrows (asplake)" <m...@asplake.co.uk>
Date: Tue, 3 Nov 2009 01:46:40 -0800 (PST)
Local: Tues 3 Nov 2009 09:46
Subject: Re: Repeating elements and htmlfill
Thanks, variable_encode did the trick.

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

    print htmlfill.render(
                    '<input id="weightings-0.weight"
name="weightings-0.weight" type="text" value="" />',
                    variable_encode({'weightings': [{'weight':
"1.0"}]}))

Easy when you know how!

Regards,
Mike


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Burrows (asplake)  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 12:38
From: "Mike Burrows (asplake)" <m...@asplake.co.uk>
Date: Thu, 5 Nov 2009 04:38:53 -0800 (PST)
Local: Thurs 5 Nov 2009 12:38
Subject: Re: Repeating elements and htmlfill

DRY'ed up my code, solution posted here: http://positiveincline.com/?p=540

Thanks again,
Mike


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 16:07
From: Chris <fractalbynat...@gmail.com>
Date: Thu, 5 Nov 2009 08:07:14 -0800 (PST)
Local: Thurs 5 Nov 2009 16:07
Subject: Re: Repeating elements and htmlfill
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:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Burrows (asplake)  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 07:28
From: "Mike Burrows (asplake)" <m...@asplake.co.uk>
Date: Thu, 5 Nov 2009 23:28:38 -0800 (PST)
Local: Fri 6 Nov 2009 07:28
Subject: Re: Repeating elements and htmlfill
Hi Chris,

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:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google