[web2py] Re: cancel button in update and create work differently [closed]

2010-06-01 Thread annet
Yes, you're right, I hadn't thought of that. Thanks for providing me
with a better solution.


Kind regards,

Annet.


[web2py] Re: cancel button in update and create work differently [closed]

2010-06-01 Thread Iceberg
history.go(-1) will not work if the current page is the first page of
current browser session.

Will this help you?  


On Jun1, 8:00pm, annet  wrote:
> Setting the cancel button to:
>
> form[0][-1]
> [1].append(INPUT(_type="button",_value="Cancel",_onclick='javascript:histor 
> y.go(-1);'))
>
> at least gives the user a way to cancel the function, not the way I
> wanted it, but it's better than getting an error.
>
> Annet


[web2py] Re: cancel button in update and create work differently [closed]

2010-06-01 Thread annet
Setting the cancel button to:

form[0][-1]
[1].append(INPUT(_type="button",_value="Cancel",_onclick='javascript:history.go(-1);'))

at least gives the user a way to cancel the function, not the way I
wanted it, but it's better than getting an error.


Annet


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.



[web2py] Re: cancel button

2010-02-16 Thread mdipierro
   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):
  del request.vars.button
  ...update/insert logic...



On Feb 16, 2: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. But the sql on the form.accepts path craps
> out:
>
> S'Traceback (most recent call last):\n  File "gluon/restricted.py",
> line 173, in restricted\n  File "w:\\web2py_win\\applications\
> \canyonezt/controllers/default.py", line 184, in \n  File
> "gluon/globals.py", line 96, in \n  File "gluon/tools.py",
> line 1851, in f\n  File "w:\\web2py_win\\applications\\canyonezt/
> controllers/default.py", line 152, in profile\n  File "gluon/sql.py",
> line 1877, in insert\n  File "gluon/sql.py", line 1845, in _insert
> \nSyntaxError: invalid field names: [\'button\']\n'
>
> It looks like the DAL is trying to store 'button' in my data base,
> though it is unclear to me why. What's the secret, here?

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



[web2py] Re: cancel button

2010-02-16 Thread reyelts
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. But the sql on the form.accepts path craps
out:

S'Traceback (most recent call last):\n  File "gluon/restricted.py",
line 173, in restricted\n  File "w:\\web2py_win\\applications\
\canyonezt/controllers/default.py", line 184, in \n  File
"gluon/globals.py", line 96, in \n  File "gluon/tools.py",
line 1851, in f\n  File "w:\\web2py_win\\applications\\canyonezt/
controllers/default.py", line 152, in profile\n  File "gluon/sql.py",
line 1877, in insert\n  File "gluon/sql.py", line 1845, in _insert
\nSyntaxError: invalid field names: [\'button\']\n'

It looks like the DAL is trying to store 'button' in my data base,
though it is unclear to me why. What's the secret, here?

-- 
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  wrote:
>> The patch will be in soon. ;-)
>> 
>> On Feb 7, 4:18 pm, Jonathan Lundell  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.



[web2py] Re: cancel button

2010-02-07 Thread mdipierro
The patch by Mr Freeze is in.

On Feb 7, 4:27 pm, mdipierro  wrote:
> The patch will be in soon. ;-)
>
> On Feb 7, 4:18 pm, Jonathan Lundell  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-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.



[web2py] Re: cancel button

2010-02-07 Thread mdipierro
The patch will be in soon. ;-)


On Feb 7, 4:18 pm, Jonathan Lundell  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-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.



[web2py] Re: cancel button

2010-02-07 Thread mr.freeze
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?

On Feb 7, 3:24 pm, Jonathan Lundell  wrote:
> On Feb 6, 2010, at 9:33 PM, Iceberg wrote:
>
>
>
> > On Feb7, 8:01am, Jonathan Lundell  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  
> 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 6, 2010, at 9:33 PM, Iceberg wrote:

> On Feb7, 8:01am, Jonathan Lundell  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  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.



[web2py] Re: cancel button

2010-02-06 Thread weheh
Is it reasonable to expect this to work on crud forms, as well? I
would think so, but I'm having difficulty getting it to work.

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



[web2py] Re: cancel button

2010-02-06 Thread Iceberg
On Feb7, 8:01am, Jonathan Lundell  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 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.


>
> 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'),
)

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



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



[web2py] Re: cancel button

2010-02-06 Thread mdipierro
form[0][-1][1].append(BUTTON(_onclick=""))

On Feb 6, 12:09 pm, Jonathan Lundell  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.