|
From: Chris L. <ch...@ka...> - 2012-07-12 14:37:27
|
Hi,
htmlfill does not need to take a whole page as input and running htmlfill
over a particular form is likely to give you the result you want (see
below). However, your second suggestion sounds like a good one, and I would
also consider a patch teaching htmlfill about more than one form.
The easiest way to do this will htmlfill as it is now will depend on how
you render your pages. I'll use Mako, as an example. You can create a def
for the form something like this:
<%def name="renderform()" buffer="True">
<input type="text" name="name" value="fill">
<select name="occupation"> <option value="">Default</option>
<option value="Crazy Cultist">Crazy cultist</option> </select>
<textarea cols="20" style="width: 100%" name="address">
An address</textarea>
<input type="radio" name="living" value="yes">
<input type="radio" name="living" value="no">
<input type="checkbox" name="nice_guy" checked="checked">
</%def>
and then place the form and htmlfill it like so:
<% defaults = dict(name='Bob Jones',
occupation='Crazy Cultist',
address='14 W. Canal\nNew Guinea',
living='no',
nice_guy=0)
%>
${htmlfill.render(renderform(), defaults)}
will result in:
<input type="text" name="name" value="Bob Jones">
<select name="occupation">
<option value="">Default</option>
<option value="Crazy Cultist" selected="selected">Crazy cultist</option>
</select>
<textarea cols="20" style="width: 100%" name="address">14 W. Canal
New Guinea</textarea>
<input type="radio" name="living" value="yes">
<input type="radio" name="living" value="no" checked="checked">
<input type="checkbox" name="nice_guy">
This limits the htmlfill to the one form in question.
You can probably pass the result of functools.partial from your controller
to have the defaults, errors, etc all pre-bound to the function ahead of
time. Something like:
formfillfn = functools.partial(htmlfill.render,
defaults=pre_computed_defaults, errors=pre_computed_errors)
then the call above can be changed to filter syntax:
${renderform() | formfillfn}
I don't use Jinja but it looks like you could do this for the
functools.partial method:
{% filter formfillfn %}
<input type="text" name="name" value="fill">
<select name="occupation"> <option value="">Default</option>
<option value="Crazy Cultist">Crazy cultist</option> </select>
<textarea cols="20" style="width: 100%" name="address">
An address</textarea>
<input type="radio" name="living" value="yes">
<input type="radio" name="living" value="no">
<input type="checkbox" name="nice_guy" checked="checked">
{% endfilter %}
-Chris
On Wed, Jul 11, 2012 at 6:48 PM, Jonathan Vanasco <jva...@2x...> wrote:
> hoping someone can give me a suggestion :
>
> I sometimes have two forms displayed on a single page. They're validated
> separately and submitted to different locations. ( this is under pylons
> and pyramid )
>
> example:
> the left side of the screen shows Account Data
> the right side of the screen has a "change password" and "change
> email" field
>
>
> If i use htmlfill.render on this page to reprint on an error the following
> behavior happens:
>
> 1) default settings
> - the validated form looks like i want it to
> -- there are errors displayed
> -- the 'invalid' fields are blank
> -- the 'valid' fields are filled
> - the non-validated forms are all blank
>
> 2) force_defaults=False
> - the non-validated forms have their default values
> - the validated form loses all the submitted values
>
> does anyone have a suggestion on how i can achieve this:
>
> - the non-validated forms have their default values
> - the validated form has the submitted values &
> errors/blanks
>
> the ideas i have so far are:
> - push the defaults from the other form into the validated form's
> defaults
> - add a kwarg to htmlfill.render that would only allow the form
> re-writing to affect fields explicitly listed in `defaults` and `errors`
>
> it'll probably take me as much time to code either of these solutions. if
> the community would benefit from the second idea - i'd be happy to write a
> patch.
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> FormEncode-discuss mailing list
> For...@li...
> https://lists.sourceforge.net/lists/listinfo/formencode-discuss
>
--
Christopher Lambacher
ch...@ka...
|