Re: [web2py] Re: cancel button

2010-02-16 Thread Jonathan Lundell
On Feb 16, 2010, at 12:18 PM, reyelts wrote:

 I'm trying to use this with my shiny new SQLFORM. But I'm clearly
 missing something. Here's a snippet:
 
   form = SQLFORM(...blah...)
   submit = form.element(_type='submit')
 
 submit.parent.append(INPUT(_type='submit',_value='Cancel',_name='button'))
 
   if request.vars.button == 'Cancel':
  session.flash = 'profile create was cancelled'
  session.flash = 'profile update was cancelled'
  redirect(URL(r=request,f='index'))
   elif form.accepts(request.vars,session,dbio=False):
  ...update/insert logic...
 
 The cancel works perfectly.

A problem that someone mentioned recently (or at least alluded to) is that 
there's an issue with IE and multiple submit buttons, namely that if the user 
types a return in a form field, you aren't guaranteed that you'll see the first 
submit button. So somebody might type a return, and  you'll see a cancel.

So I ended up with _type='button', and an onclick script to provide the URL. So 
far so good

-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



Re: [web2py] Re: cancel button

2010-02-07 Thread Jonathan Lundell
On Feb 6, 2010, at 9:33 PM, Iceberg wrote:

 On Feb7, 8:01am, Jonathan Lundell jlund...@pobox.com wrote:
 On Feb 6, 2010, at 12:58 PM, Jonathan Lundell wrote:
 
 On Feb 6, 2010, at 12:38 PM, mdipierro wrote:
 
 form[0][-1][1].append(BUTTON(_onclick=))
 
 Thanks.
 
 Ideally, I'd like to return to the form.accepts call in such a way that the 
 accepts return test can recognize the cancelation and then redirect as 
 necessary. Somewhat parallel to testing form.error, I'd test (say) 
 form.cancel.
 
 Does that make sense? It seems to me that it might be a useful general 
 capability for form processing.
 
 One angle I was thinking of, but haven't investigated, is having multiple 
 submit buttons, with accepts() making available the name and/or value of 
 the button that was clicked.
 
 That seems more in keeping with the self-submit philosophy, don't you think?
 
 
 Yes, but be careful of multiple submit buttons. See this post:
  https://groups.google.com/group/web2py/browse_frm/thread/f44b6f95b058df5

I'll need to look at that more closely. Thanks. Perhaps I can use button and 
JavaScript.

 
 
 I think I got it to work.
 
 form[0][-1][1].append(INPUT(_type=submit, _name=button, 
 _value=Cancel))
 
 and then after calling accepts:
 
 if request.vars.button == Cancel:
 session.flash = 'edit canceled'
 else:
 session.flash = edit accepted
 redirect(URL(r=request, f='servers'))
 
 ...or something similar in the form.error case.
 
 (I find that I'm a little fuzzy on the various return cases for accepts, 
 though.)
 
 That is inevitable since you need to handle two different situations
 in one action. So I would suggest just use a normal html reset button
 at most.

Reset doesn't do it for me; I need an actual cancel function that can do a 
specified page load.

 
 
 
 Question: what exactly is form[0][-1][1].append appending to? Can I append 
 more than once to that same object?
 
 Yes. FORM is a container for many components. You can change it if you
 want to. But a more readable style should be:
  form = FORM(
... # all the normal stuff
INPUT(_type='submit'),
INPUT(_type='reset'),
)

Except it's an SQLFORM, which won't accept INPUT arguments.

The big problem with form[0][-1][1].append is that it knows too much about 
the internal structure of form. I can't expect the guarantee of backward 
compatibility to include constructs like that.


So I'm left with two problems. The IE with multiple submits, and adding a 
button to the SQLFORM. Both are semi-solved, I think, but not in an ideal way.

-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



Re: [web2py] Re: cancel button

2010-02-07 Thread Jonathan Lundell
On Feb 7, 2010, at 2:06 PM, mr.freeze wrote:

 I hate this too: form[0][-1][1]. I have a pending patch that will
 allow you to grab parent and sibling elements so you can do:
 form = SQLFORM(db.whatever)
 submit = form.element(_type='submit')
 submit.parent.append(INPUT(_type='submit',_value='Cancel'))
 
 A little more verbose but human readable and appending the button will
 stay relative to where the submit button is.
 
 Massimo, have you had a chance to look at this?

That would be a big improvement, yes.

-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



Re: [web2py] Re: cancel button

2010-02-07 Thread Jonathan Lundell
On Feb 6, 2010, at 9:33 PM, Iceberg wrote:

 Yes, but be careful of multiple submit buttons. See this post:
  https://groups.google.com/group/web2py/browse_frm/thread/f44b6f95b058df5

I think I've solved the multiple-submit problem, at the cost of a bit of 
scripting (but not much):

form[0][-1][1].append(INPUT(_type=button, _value=Cancel, 
_onclick=location='%s';%URL(r=request, f='addserver', 
vars=dict(button='Cancel'

-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



Re: [web2py] Re: cancel button

2010-02-07 Thread Jonathan Lundell
On Feb 7, 2010, at 6:31 PM, mdipierro wrote:

 The patch by Mr Freeze is in.

Thanks. I'll wait for a stable release, but I'll definitely use it.

Some documentary comments would be nice.

(BTW, the patch added trailing white space to a few lines. Bogus, I assume.)

 
 On Feb 7, 4:27 pm, mdipierro mdipie...@cs.depaul.edu wrote:
 The patch will be in soon. ;-)
 
 On Feb 7, 4:18 pm, Jonathan Lundell jlund...@pobox.com wrote:
 
 On Feb 7, 2010, at 2:06 PM, mr.freeze wrote:
 
 I hate this too: form[0][-1][1]. I have a pending patch that will
 allow you to grab parent and sibling elements so you can do:
 form = SQLFORM(db.whatever)
 submit = form.element(_type='submit')
 submit.parent.append(INPUT(_type='submit',_value='Cancel'))
 
 A little more verbose but human readable and appending the button will
 stay relative to where the submit button is.
 
 Massimo, have you had a chance to look at this?
 
 That would be a big improvement, yes.


-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



Re: [web2py] Re: cancel button

2010-02-06 Thread Jonathan Lundell
On Feb 6, 2010, at 12:38 PM, mdipierro wrote:

 form[0][-1][1].append(BUTTON(_onclick=))

Thanks.

Ideally, I'd like to return to the form.accepts call in such a way that the 
accepts return test can recognize the cancelation and then redirect as 
necessary. Somewhat parallel to testing form.error, I'd test (say) form.cancel. 

Does that make sense? It seems to me that it might be a useful general 
capability for form processing.

One angle I was thinking of, but haven't investigated, is having multiple 
submit buttons, with accepts() making available the name and/or value of the 
button that was clicked.

That seems more in keeping with the self-submit philosophy, don't you think?

 
 On Feb 6, 12:09 pm, Jonathan Lundell jlund...@pobox.com wrote:
 I seem to be full of elementary questions this week.
 
 I've got a simple SQLFORM to add a row to a database, and I want to have a 
 cancel button along with the submit button.
 
 How?
 


-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



Re: [web2py] Re: cancel button

2010-02-06 Thread Jonathan Lundell
On Feb 6, 2010, at 12:58 PM, Jonathan Lundell wrote:

 On Feb 6, 2010, at 12:38 PM, mdipierro wrote:
 
 form[0][-1][1].append(BUTTON(_onclick=))
 
 Thanks.
 
 Ideally, I'd like to return to the form.accepts call in such a way that the 
 accepts return test can recognize the cancelation and then redirect as 
 necessary. Somewhat parallel to testing form.error, I'd test (say) 
 form.cancel. 
 
 Does that make sense? It seems to me that it might be a useful general 
 capability for form processing.
 
 One angle I was thinking of, but haven't investigated, is having multiple 
 submit buttons, with accepts() making available the name and/or value of the 
 button that was clicked.
 
 That seems more in keeping with the self-submit philosophy, don't you think?

I think I got it to work.

form[0][-1][1].append(INPUT(_type=submit, _name=button, 
_value=Cancel))

and then after calling accepts:

if request.vars.button == Cancel:
session.flash = 'edit canceled'
else:
session.flash = edit accepted
redirect(URL(r=request, f='servers'))

...or something similar in the form.error case. (I find that I'm a little fuzzy 
on the various return cases for accepts, though.)

Question: what exactly is form[0][-1][1].append appending to? Can I append more 
than once to that same object?

-- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.