On Oct 30, 2007, at 12:49 PM, Michael Watkins wrote: > * David K. Hess wrote on [2007-10-30 11:31:41 -0500]: >> 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. > > A HTML 'reset' resets the form purely on the client side; there is > no POST to the server. While its handy and useful: > > form.add_reset('reset', 'Reset') > > .... its probably not what you want. > > If I read you correctly, you: > > - have more than one form on a page > - take some action based on the completion of one of the forms (lets > call it form A) perhaps modifying what should be presented in the > Response sent to the client after that form is POSTed. > - Want to reset form A to blank or default values after it is > POSTed. > - Presumably you ignore form A if form B was submitted > > This reminds me a little of OptionSelectWidget by the way. > > You could (almost) get there by doing something like: > > def edit [html] (): > > form_a = form_a_form(default, value, here) > form_b = form_b_form(some, other, values) > > if not form_b.is_submitted() or form_b.has_errors(): > if form_a.is_submitted(): > do_something_with_values(form_a) > form_a = form_a_form(default, value, here) > return page('Edit', > form_a.render(), > form_b.render()) This approach is what I'm contemplating. I.e. process one copy of the form for submission and get a new copy of the form that hasn't been touched by is_submitted or has_errors for rendering. > I say (almost) because Form.is_submitted() doesn't discriminate > between forms - it processes all the fields in a Request and sets > all to '' if they are not present in the Request. Your form_a gets > processed correctly, but form_b is set to blank. > > Perhaps Form should include a form "id" prefix which all widgets > construct field names unique to the form which defines them; then > processing one form on a page won't clobber the balance. David B., et. al. added the "prefix" keyword to Form in qp 2.0 which makes this possible now. (Thanks MEMS folks!) In my particular case, I'm rendering a table with one form on every row (a submit button to delete the row) and a form at the bottom of the page to add a new item. The "prefix" keyword is used to keep all of them separate and correlated with the rows. All of the forms on the page post to the same url that renders the table and the form processing is embedded within the table rendering. I just check each form to see which one was submitted and skip rendering a row if it got deleted. What I'd like though is for the add form at the bottom to be blank after being used to add a new row to the table. This is a little bit different then the typical approach to object- oriented CRUD in qp but it makes for a very efficient, compact and responsive user interface for simpler/ smaller operations. No redirects, no intermediate pages and no need to factor rendering into more than one place. Dave