durusmail: qp: Form reset?
Form reset?
2007-10-18
2007-10-29
2007-10-29
2007-10-29
2007-10-29
2007-10-30
2007-10-30
2007-10-30
2007-10-30
2007-10-30
Re: Form reset?
2007-10-30
2007-10-30
2007-10-30
2007-11-02
2007-11-19
Form reset?
mario ruggier
2007-10-30
On Oct 30, 2007, at 5:31 PM, David K. Hess wrote:
> I'm not sure how I would apply that outside of an AJAX setting? I'm
> trying to reset the values of the form after it has been submitted but
> before it has been rendered for return to the client.

I had a similar problem (I think, if i understand you correctly) and
that was to be able to apply field values (arbitrarily, depending on
some dynamic condition) onto a form (that is submitted or not).

I had opted for doing it as I describe below, but always had it in the
back of my mind that a rethink of how Form works for this is probably
needed -- I feel that there should be better support for a real
widget.set_value(), that is independent (a) of the widget's default
(init) value (b) of the incoming value in the request.fields dict (c)
of whether the widget is "parsed" or not.

The logic for setting widget values seems (to me) too tangled up with
the logic for parsing incoming values on the request -- and instead of
trying to "untangle" that logic I just opted to "adjust" the incoming
values on the request...

If you wish to look at the code in its real context, to maybe
understand the idea more clearly and whether it is applicable to your
problem or not, you may look at the gz.gizmo.gform module. In that, the
base GWidget has this method:

     def unparse(self, value, request):
         # Does opposite of parse -- pushes a stored value onto request
field.
         # Useful to "prefill" incoming form field widget from a stored
value.
         self._parsed = False
         request.fields[self.name] = value

The "unparse" for some actual widgets assumed a variation of this, e.g.
the one for SingleSelect and Date.

In your case I think you may want to reset values to some default set
of values (i.e always the same), but maybe the same technique may
apply.

> I suppose one way to use that would be to have some javascript that
> does a form reset on the client after it loads the form...?

Submitting via AJAX changes the game significantly...but iiuc you are
submitting normally (form.action), i.e. reloading the entire page? If
so, having to return the rendered form with previously submitted values
that you want to clean up, and then sending js to the client to do the
cleaning up (I think client-side form.reset() resets the form to the
initial values that it was loaded with) seems probably too error-prone
(and maybe too much work!).

mario


> Dave
>
> On Oct 30, 2007, at 4:53 AM, David Binger wrote:
>
>>
>> On Oct 29, 2007, at 12:41 PM, David K. Hess wrote:
>>
>>>
>>> I would like to process a submitted form, reset it back to
>>> default/empty and then render it again in one request. This is for a
>>> page with multiple forms on it.
>>>
>>> I'd like to avoid a redirect as I may set some values in other forms
>>> or change the way the page renders based on what was in the
>>> submitted one.
>>
>> Would an INPUT tag with type="reset" be useful in this situation?

reply