Re: [web2py] Re: Add button to form & access from view

2012-12-18 Thread Massimo Di Pierro
There are some design issues here. The main think is that you click on the 
button you want something to happen without the reloading the page. Yet you 
make the callback=URL() point to the same action that generates the 
page while it should point to a separate action which just performs the 
callback. You need two actions. One renders the page and one deals with the 
callback events.

For example:

db.define_table('friend',Field('name'))

def manage(): # renders page
form = SQLFORM(db.friend)
friends = db(db.friend).select()
return dict(form=form,friends=friends)

def delete_friend(): # executes callback
# should check permissions but ok for now...
del db.friend[request.port_vars.id]
return 'done'

% views/default/manage.html

{{extend 'layout.html'}}
{{=form}}

{{for friend in friends:}}
  
{{=friend.name}}

{{=A('delete',callback=URL('delete_friend',vars=dict(id=friend.id),delete='tr'))}}
  
{{pass}}


On Tuesday, 18 December 2012 11:15:15 UTC-6, Daniele wrote:
>
> Sure thing Massimo,
>
> here's my view: http://bpaste.net/show/nSrzmYsurH2CnXLrpdwJ/
>
> here's my controller: http://bpaste.net/show/KEx38v6ARYgsUwG8oXMd/
>
> Daniele
>
>
> On Tue, Dec 18, 2012 at 5:07 PM, Massimo Di Pierro 
> 
> > wrote:
>
>> Please post your code so we can try it. 
>>
>> Are you sure the edit_profile is not being called? Can you use the JS 
>> console in chorme to see what is going on?
>>
>> Massimo
>>
>> On Tuesday, 18 December 2012 10:49:28 UTC-6, Daniele wrote:
>>>
>>> Still isn't working for me :'(
>>>
>>> In my view, I have:
>>> {{=A('Delete Role',_class="btn 
>>> btn-danger",_id='deltutorlink'**, callback=URL('edit_profile'),**
>>> delete='#deltutor')}
>>>
>>> in my controller, under the edit_profile method, I have:
>>>
>>> if request.vars.deltutorlink:
>>> response.flash = T('deltutorlink reached!')
>>>
>>> but this response.flash is never reached. I can't figure out why
>>>
>>>
>>> On Saturday, December 15, 2012 7:36:34 PM UTC, Massimo Di Pierro wrote:

  {{=A('delete 
 123',callback=URL('delete',**args=123),delete='#row123')}} 
 ... 


 The delete argument indicates that upon success you want to remove the 
 ... from the page. If there is a "delete" argument 
 the confirmation popup is automatic. ;-)

 On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:
>
> I want to do something very simple but it's taking me eons to do this~
>
> When the button is clicked, I want a javascript alert to pop up that 
> asks, are you sure? Yes/No.
> If Yes, then run this code: auth.del_membership('role')
>
> No redirection, just delete the role.
> That's all -_- this is taking me way too long
>
> On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:
>>
>> None. You are asking to ":eval" the result. It meas the action is 
>> supposed to return JS
>>
>> def test():
>> return "alert('hello')"
>>
>> anyway, you should debug this with the JS console in chrome. We do 
>> not know exactly how your code looks like.
>>
>> On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>>>
>>> I am trying with:
>>> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
>>> callback=URL('test'), target=":eval")}}
>>>
>>> and in my controller:
>>>
>>> def test():
>>> return "Hello"
>>>
>>> or 
>>>
>>> def test():
>>> return dict()
>>>
>>> but when I click the button, nothing happens. Why is this??
>>>
>>> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:

 When I use form.add_button() I am able to add a button to a form, 
 which I can display with {{=form}} in my view.

 However, if I'm making a custom form using form.custom, how can I 
 display that button??

 Thanks

>>>  -- 
>>  
>>  
>>  
>>
>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-18 Thread Daniele
I tried doing this but absolutely nothing happens when I click the button

On Tuesday, December 18, 2012 5:10:01 PM UTC, Massimo Di Pierro wrote:
>
> BTW...
>
> def edit_record():
> ...
> if request.vars.deltutorlink:
> response.flash = T('deltutorlink reached!')
> ...
>
> If edit_record is called via ajax and not within a component, 
> than response.flash is not displayed because there is no view associated to 
> the callback. You can do:
>
> def edit_record():
> ...
> if request.vars.deltutorlink:
> response.js = "jQuery('.flash').html('deltutorlink 
> reached!').slideDown()"
> ...
>
> and the response flash will be injected in the proper place.
>
>
> On Tuesday, 18 December 2012 10:49:28 UTC-6, Daniele wrote:
>>
>> Still isn't working for me :'(
>>
>> In my view, I have:
>> {{=A('Delete Role',_class="btn 
>> btn-danger",_id='deltutorlink', 
>> callback=URL('edit_profile'),delete='#deltutor')}
>>
>> in my controller, under the edit_profile method, I have:
>>
>> if request.vars.deltutorlink:
>> response.flash = T('deltutorlink reached!')
>>
>> but this response.flash is never reached. I can't figure out why
>>
>>
>> On Saturday, December 15, 2012 7:36:34 PM UTC, Massimo Di Pierro wrote:
>>>
>>>  {{=A('delete 
>>> 123',callback=URL('delete',args=123),delete='#row123')}} ... 
>>>
>>>
>>> The delete argument indicates that upon success you want to remove the 
>>> ... from the page. If there is a "delete" argument 
>>> the confirmation popup is automatic. ;-)
>>>
>>> On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:

 I want to do something very simple but it's taking me eons to do this~

 When the button is clicked, I want a javascript alert to pop up that 
 asks, are you sure? Yes/No.
 If Yes, then run this code: auth.del_membership('role')

 No redirection, just delete the role.
 That's all -_- this is taking me way too long

 On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:
>
> None. You are asking to ":eval" the result. It meas the action is 
> supposed to return JS
>
> def test():
> return "alert('hello')"
>
> anyway, you should debug this with the JS console in chrome. We do not 
> know exactly how your code looks like.
>
> On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>>
>> I am trying with:
>> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
>> callback=URL('test'), target=":eval")}}
>>
>> and in my controller:
>>
>> def test():
>> return "Hello"
>>
>> or 
>>
>> def test():
>> return dict()
>>
>> but when I click the button, nothing happens. Why is this??
>>
>> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>>
>>> When I use form.add_button() I am able to add a button to a form, 
>>> which I can display with {{=form}} in my view.
>>>
>>> However, if I'm making a custom form using form.custom, how can I 
>>> display that button??
>>>
>>> Thanks
>>>
>>

-- 





Re: [web2py] Re: Add button to form & access from view

2012-12-18 Thread Daniele Pestilli
Sure thing Massimo,

here's my view: http://bpaste.net/show/nSrzmYsurH2CnXLrpdwJ/

here's my controller: http://bpaste.net/show/KEx38v6ARYgsUwG8oXMd/

Daniele


On Tue, Dec 18, 2012 at 5:07 PM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> Please post your code so we can try it.
>
> Are you sure the edit_profile is not being called? Can you use the JS
> console in chorme to see what is going on?
>
> Massimo
>
> On Tuesday, 18 December 2012 10:49:28 UTC-6, Daniele wrote:
>>
>> Still isn't working for me :'(
>>
>> In my view, I have:
>> {{=A('Delete Role',_class="btn
>> btn-danger",_id='deltutorlink'**, callback=URL('edit_profile'),**
>> delete='#deltutor')}
>>
>> in my controller, under the edit_profile method, I have:
>>
>> if request.vars.deltutorlink:
>> response.flash = T('deltutorlink reached!')
>>
>> but this response.flash is never reached. I can't figure out why
>>
>>
>> On Saturday, December 15, 2012 7:36:34 PM UTC, Massimo Di Pierro wrote:
>>>
>>>  {{=A('delete 
>>> 123',callback=URL('delete',**args=123),delete='#row123')}}
>>> ... 
>>>
>>>
>>> The delete argument indicates that upon success you want to remove the
>>> ... from the page. If there is a "delete" argument
>>> the confirmation popup is automatic. ;-)
>>>
>>> On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:

 I want to do something very simple but it's taking me eons to do this~

 When the button is clicked, I want a javascript alert to pop up that
 asks, are you sure? Yes/No.
 If Yes, then run this code: auth.del_membership('role')

 No redirection, just delete the role.
 That's all -_- this is taking me way too long

 On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:
>
> None. You are asking to ":eval" the result. It meas the action is
> supposed to return JS
>
> def test():
> return "alert('hello')"
>
> anyway, you should debug this with the JS console in chrome. We do not
> know exactly how your code looks like.
>
> On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>>
>> I am trying with:
>> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor",
>> callback=URL('test'), target=":eval")}}
>>
>> and in my controller:
>>
>> def test():
>> return "Hello"
>>
>> or
>>
>> def test():
>> return dict()
>>
>> but when I click the button, nothing happens. Why is this??
>>
>> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>>
>>> When I use form.add_button() I am able to add a button to a form,
>>> which I can display with {{=form}} in my view.
>>>
>>> However, if I'm making a custom form using form.custom, how can I
>>> display that button??
>>>
>>> Thanks
>>>
>>  --
>
>
>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-18 Thread Massimo Di Pierro
BTW...

def edit_record():
...
if request.vars.deltutorlink:
response.flash = T('deltutorlink reached!')
...

If edit_record is called via ajax and not within a component, 
than response.flash is not displayed because there is no view associated to 
the callback. You can do:

def edit_record():
...
if request.vars.deltutorlink:
response.js = "jQuery('.flash').html('deltutorlink 
reached!').slideDown()"
...

and the response flash will be injected in the proper place.


On Tuesday, 18 December 2012 10:49:28 UTC-6, Daniele wrote:
>
> Still isn't working for me :'(
>
> In my view, I have:
> {{=A('Delete Role',_class="btn 
> btn-danger",_id='deltutorlink', 
> callback=URL('edit_profile'),delete='#deltutor')}
>
> in my controller, under the edit_profile method, I have:
>
> if request.vars.deltutorlink:
> response.flash = T('deltutorlink reached!')
>
> but this response.flash is never reached. I can't figure out why
>
>
> On Saturday, December 15, 2012 7:36:34 PM UTC, Massimo Di Pierro wrote:
>>
>>  {{=A('delete 
>> 123',callback=URL('delete',args=123),delete='#row123')}} ... 
>>
>>
>> The delete argument indicates that upon success you want to remove the 
>> ... from the page. If there is a "delete" argument 
>> the confirmation popup is automatic. ;-)
>>
>> On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:
>>>
>>> I want to do something very simple but it's taking me eons to do this~
>>>
>>> When the button is clicked, I want a javascript alert to pop up that 
>>> asks, are you sure? Yes/No.
>>> If Yes, then run this code: auth.del_membership('role')
>>>
>>> No redirection, just delete the role.
>>> That's all -_- this is taking me way too long
>>>
>>> On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:

 None. You are asking to ":eval" the result. It meas the action is 
 supposed to return JS

 def test():
 return "alert('hello')"

 anyway, you should debug this with the JS console in chrome. We do not 
 know exactly how your code looks like.

 On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>
> I am trying with:
> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
> callback=URL('test'), target=":eval")}}
>
> and in my controller:
>
> def test():
> return "Hello"
>
> or 
>
> def test():
> return dict()
>
> but when I click the button, nothing happens. Why is this??
>
> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>
>> When I use form.add_button() I am able to add a button to a form, 
>> which I can display with {{=form}} in my view.
>>
>> However, if I'm making a custom form using form.custom, how can I 
>> display that button??
>>
>> Thanks
>>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-18 Thread Massimo Di Pierro
Please post your code so we can try it. 

Are you sure the edit_profile is not being called? Can you use the JS 
console in chorme to see what is going on?

Massimo

On Tuesday, 18 December 2012 10:49:28 UTC-6, Daniele wrote:
>
> Still isn't working for me :'(
>
> In my view, I have:
> {{=A('Delete Role',_class="btn 
> btn-danger",_id='deltutorlink', 
> callback=URL('edit_profile'),delete='#deltutor')}
>
> in my controller, under the edit_profile method, I have:
>
> if request.vars.deltutorlink:
> response.flash = T('deltutorlink reached!')
>
> but this response.flash is never reached. I can't figure out why
>
>
> On Saturday, December 15, 2012 7:36:34 PM UTC, Massimo Di Pierro wrote:
>>
>>  {{=A('delete 
>> 123',callback=URL('delete',args=123),delete='#row123')}} ... 
>>
>>
>> The delete argument indicates that upon success you want to remove the 
>> ... from the page. If there is a "delete" argument 
>> the confirmation popup is automatic. ;-)
>>
>> On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:
>>>
>>> I want to do something very simple but it's taking me eons to do this~
>>>
>>> When the button is clicked, I want a javascript alert to pop up that 
>>> asks, are you sure? Yes/No.
>>> If Yes, then run this code: auth.del_membership('role')
>>>
>>> No redirection, just delete the role.
>>> That's all -_- this is taking me way too long
>>>
>>> On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:

 None. You are asking to ":eval" the result. It meas the action is 
 supposed to return JS

 def test():
 return "alert('hello')"

 anyway, you should debug this with the JS console in chrome. We do not 
 know exactly how your code looks like.

 On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>
> I am trying with:
> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
> callback=URL('test'), target=":eval")}}
>
> and in my controller:
>
> def test():
> return "Hello"
>
> or 
>
> def test():
> return dict()
>
> but when I click the button, nothing happens. Why is this??
>
> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>
>> When I use form.add_button() I am able to add a button to a form, 
>> which I can display with {{=form}} in my view.
>>
>> However, if I'm making a custom form using form.custom, how can I 
>> display that button??
>>
>> Thanks
>>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-18 Thread Daniele
Still isn't working for me :'(

In my view, I have:
{{=A('Delete Role',_class="btn 
btn-danger",_id='deltutorlink', 
callback=URL('edit_profile'),delete='#deltutor')}

in my controller, under the edit_profile method, I have:

if request.vars.deltutorlink:
response.flash = T('deltutorlink reached!')

but this response.flash is never reached. I can't figure out how to get the 
callback go to the controller and pass in the request.vars.deltutorlink as 
being clicked so that it can run the code I want...


On Saturday, December 15, 2012 7:36:34 PM UTC, Massimo Di Pierro wrote:
>
>  {{=A('delete 
> 123',callback=URL('delete',args=123),delete='#row123')}} ... 
>
>
> The delete argument indicates that upon success you want to remove the 
> ... from the page. If there is a "delete" argument 
> the confirmation popup is automatic. ;-)
>
> On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:
>>
>> I want to do something very simple but it's taking me eons to do this~
>>
>> When the button is clicked, I want a javascript alert to pop up that 
>> asks, are you sure? Yes/No.
>> If Yes, then run this code: auth.del_membership('role')
>>
>> No redirection, just delete the role.
>> That's all -_- this is taking me way too long
>>
>> On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:
>>>
>>> None. You are asking to ":eval" the result. It meas the action is 
>>> supposed to return JS
>>>
>>> def test():
>>> return "alert('hello')"
>>>
>>> anyway, you should debug this with the JS console in chrome. We do not 
>>> know exactly how your code looks like.
>>>
>>> On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:

 I am trying with:
 {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
 callback=URL('test'), target=":eval")}}

 and in my controller:

 def test():
 return "Hello"

 or 

 def test():
 return dict()

 but when I click the button, nothing happens. Why is this??

 On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, 
> which I can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I 
> display that button??
>
> Thanks
>


-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Massimo Di Pierro
 {{=A('delete 
123',callback=URL('delete',args=123),delete='#row123')}} ... 


The delete argument indicates that upon success you want to remove the ... from the page. If there is a "delete" argument the 
confirmation popup is automatic. ;-)

On Saturday, 15 December 2012 11:35:28 UTC-6, Daniele wrote:
>
> I want to do something very simple but it's taking me eons to do this~
>
> When the button is clicked, I want a javascript alert to pop up that asks, 
> are you sure? Yes/No.
> If Yes, then run this code: auth.del_membership('role')
>
> No redirection, just delete the role.
> That's all -_- this is taking me way too long
>
> On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:
>>
>> None. You are asking to ":eval" the result. It meas the action is 
>> supposed to return JS
>>
>> def test():
>> return "alert('hello')"
>>
>> anyway, you should debug this with the JS console in chrome. We do not 
>> know exactly how your code looks like.
>>
>> On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>>>
>>> I am trying with:
>>> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
>>> callback=URL('test'), target=":eval")}}
>>>
>>> and in my controller:
>>>
>>> def test():
>>> return "Hello"
>>>
>>> or 
>>>
>>> def test():
>>> return dict()
>>>
>>> but when I click the button, nothing happens. Why is this??
>>>
>>> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:

 When I use form.add_button() I am able to add a button to a form, which 
 I can display with {{=form}} in my view.

 However, if I'm making a custom form using form.custom, how can I 
 display that button??

 Thanks

>>>

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Daniele
I want to do something very simple but it's taking me eons to do this~

When the button is clicked, I want a javascript alert to pop up that asks, 
are you sure? Yes/No.
If Yes, then run this code: auth.del_membership('role')

No redirection, just delete the role.
That's all -_- this is taking me way too long

On Saturday, December 15, 2012 3:32:22 PM UTC, Massimo Di Pierro wrote:
>
> None. You are asking to ":eval" the result. It meas the action is supposed 
> to return JS
>
> def test():
> return "alert('hello')"
>
> anyway, you should debug this with the JS console in chrome. We do not 
> know exactly how your code looks like.
>
> On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>>
>> I am trying with:
>> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
>> callback=URL('test'), target=":eval")}}
>>
>> and in my controller:
>>
>> def test():
>> return "Hello"
>>
>> or 
>>
>> def test():
>> return dict()
>>
>> but when I click the button, nothing happens. Why is this??
>>
>> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>>
>>> When I use form.add_button() I am able to add a button to a form, which 
>>> I can display with {{=form}} in my view.
>>>
>>> However, if I'm making a custom form using form.custom, how can I 
>>> display that button??
>>>
>>> Thanks
>>>
>>

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Massimo Di Pierro
None. You are asking to ":eval" the result. It meas the action is supposed 
to return JS

def test():
return "alert('hello')"

anyway, you should debug this with the JS console in chrome. We do not 
know exactly how your code looks like.

On Saturday, 15 December 2012 09:08:37 UTC-6, Daniele wrote:
>
> I am trying with:
> {{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
> callback=URL('test'), target=":eval")}}
>
> and in my controller:
>
> def test():
> return "Hello"
>
> or 
>
> def test():
> return dict()
>
> but when I click the button, nothing happens. Why is this??
>
> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>
>> When I use form.add_button() I am able to add a button to a form, which I 
>> can display with {{=form}} in my view.
>>
>> However, if I'm making a custom form using form.custom, how can I display 
>> that button??
>>
>> Thanks
>>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Daniele
I am trying with:
{{=A('Delete Role', _class="btn btn-danger", _id="del_role_tutor", 
callback=URL('test'), target=":eval")}}

and in my controller:

def test():
return "Hello"

or 

def test():
return dict()

but nothing happens. Why is this??

On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, which I 
> can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I display 
> that button??
>
> Thanks
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Daniele
Please pardon my ignorance, I didn't know there was a button helper.

And thanks Massimo, I'll give the A with the class btn a try now!

On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, which I 
> can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I display 
> that button??
>
> Thanks
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Massimo Di Pierro
As NIphlod says there is a BUTTON helper. Yet instead of

   Delete Role

I would do:

   {{=A('Delete Role', _id="b_normal", _class="btn btn-danger", 
callback=URL('test'), target=':eval')}}

which will look the same. Why use BUTTON when you can use A with class 
"btn" and works the same?




On Saturday, 15 December 2012 05:53:36 UTC-6, Daniele wrote:
>
> I tried putting this HTML
>  onClick="ajax('{{=URL('test')}}',[],':eval')">Delete Role
>
> which I saw on a stackoverflow post. However, even when I do that and 
> click the button, the form ALWAYS gets submitted. I already have a submit 
> button so I don't understand why the form is being submitted via other 
> buttons as well. Does anyone know why this is???
>
> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>
>> When I use form.add_button() I am able to add a button to a form, which I 
>> can display with {{=form}} in my view.
>>
>> However, if I'm making a custom form using form.custom, how can I display 
>> that button??
>>
>> Thanks
>>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Niphlod
Don't take it in the wrong way, I'll start with a little introduction: 
web2py is a framework that can do a lot of stuff. When it generates an HTML 
page the way you told him so, it returns it to the browser. From then on, 
it's just how HTML works: any button (without javascript intercepting the 
click event) included a form submits the form it's included in.

Given that you need to call a page instead of submitting the form, why 
don't you use a simple link (A()) ? 
If you need to use a button for some obscure reason to call a page, either 
you generate it OUTSIDE the form, i.e.

...





so it won't trigger the form submission, or you intercept the click in 
javascript. 
If you want to use the onclick attribute, the shortest route is including 
"return false" in the javascript bit attached to it. There are more 
elaborate and correct ways to do it but you must learn javascript first.

It's quite pathetic that web2py doesn't provide a BUTTON helper by the 
> way...
>

Please, show us with some code of what you wish for. 

>>> BUTTON()

>>> BUTTON().xml()
''
>>> BUTTON('Hello World').xml()
'Hello World'
>>> BUTTON('Hello World', _onclick="whatever").xml()
'Hello World'
>>> BUTTON('Hello World', _onclick="whatever", _href=URL('default', 'index'
)).xml()
'Hello 
World'
>>> BUTTON('Hello World', _onclick="whatever", _href=URL('default', 'index'
), _type="submit").xml()
'Hello World'
>>> BUTTON('Hello World', _onclick="whatever", _href=URL('default', 'index'
), _type="submit", _class="whateverclass").xml()
'Hello World'
>>> BUTTON('Hello World', _onclick="whatever", callback=URL('default', 
'index'), _type="submit", _class="whateverclass").xml()
'Hello 
World'



 

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Daniele
I tried putting this HTML
Delete Role

which I saw on a stackoverflow post. However, even when I do that and click 
the button, the form ALWAYS gets submitted. I already have a submit button 
so I don't understand why the form is being submitted via other buttons as 
well. Does anyone know why this is???

On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, which I 
> can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I display 
> that button??
>
> Thanks
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-15 Thread Daniele
It's quite pathetic that web2py doesn't provide a BUTTON helper by the 
way...

On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, which I 
> can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I display 
> that button??
>
> Thanks
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-14 Thread Daniele
So it's not possible to do this with a button?

On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, which I 
> can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I display 
> that button??
>
> Thanks
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-14 Thread Niphlod
onclick accepts a bit of javascript, not an url

On Friday, December 14, 2012 1:16:22 PM UTC+1, Daniele wrote:
>
> I'm also trying this but it doesn't work:
>
> Delete Role
>
> Another thing I noticed is that whatever I put in onclick, it keeps trying 
> to submit the form. I don't want to submit the form I just want the button 
> to link to an action. Any help please???
>
>
> On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>>
>> When I use form.add_button() I am able to add a button to a form, which I 
>> can display with {{=form}} in my view.
>>
>> However, if I'm making a custom form using form.custom, how can I display 
>> that button??
>>
>> Thanks
>>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-14 Thread Daniele
I'm also trying this but it doesn't work:

Delete Role



On Monday, December 10, 2012 9:15:30 PM UTC, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, which I 
> can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I display 
> that button??
>
> Thanks
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-14 Thread Daniele
I have the button 

http://127.0.0.1:8000/examples/global/vars/URL>(del_role)}}" class="btn 
btn-danger">Delete Role


And in my controller I try to put def del_role and, if the user has 
membership, i want to del_membership for that role. But this doesn't seem 
to be working. You were telling me to use _href or callback but, I don't 
think I can use those with a button html tag...


On Tuesday, December 11, 2012 2:29:58 PM UTC, Massimo Di Pierro wrote:
>
> {{=A('click me',_href=URL('action'))}} (redirects)
>
> or 
>
> {{=A('click me', callback=URL('action'))}} (call via ajax)
>
> or
>
>  {{=A('click me', callback=URL('action'),target="t")}} 
> (call via ajax and store result in t)
>
> or
>
> {{=A('click me', 
> callback=URL('action'),delete="div#c")}} (call via ajax and delete 
> button)
>
> They can be combined.
>
>
>
>
> On Tuesday, 11 December 2012 04:41:25 UTC-6, Daniele wrote:
>>
>> Ok. What's the correct way of associating an action to the HTML button 
>> with web2py?
>>
>> On Tuesday, December 11, 2012 12:30:34 AM UTC, Massimo Di Pierro wrote:
>>>
>>> This is not worth it. If you make a custom form than you are using html, 
>>> you may as well make the button in html.
>>>
>>> On Monday, 10 December 2012 15:15:30 UTC-6, Daniele wrote:

 When I use form.add_button() I am able to add a button to a form, which 
 I can display with {{=form}} in my view.

 However, if I'm making a custom form using form.custom, how can I 
 display that button??

 Thanks

>>>

-- 





[web2py] Re: Add button to form & access from view

2012-12-11 Thread Massimo Di Pierro
{{=A('click me',_href=URL('action'))}} (redirects)

or 

{{=A('click me', callback=URL('action'))}} (call via ajax)

or

 {{=A('click me', callback=URL('action'),target="t")}} 
(call via ajax and store result in t)

or

{{=A('click me', callback=URL('action'),delete="div#c")}} 
(call via ajax and delete button)

They can be combined.




On Tuesday, 11 December 2012 04:41:25 UTC-6, Daniele wrote:
>
> Ok. What's the correct way of associating an action to the HTML button 
> with web2py?
>
> On Tuesday, December 11, 2012 12:30:34 AM UTC, Massimo Di Pierro wrote:
>>
>> This is not worth it. If you make a custom form than you are using html, 
>> you may as well make the button in html.
>>
>> On Monday, 10 December 2012 15:15:30 UTC-6, Daniele wrote:
>>>
>>> When I use form.add_button() I am able to add a button to a form, which 
>>> I can display with {{=form}} in my view.
>>>
>>> However, if I'm making a custom form using form.custom, how can I 
>>> display that button??
>>>
>>> Thanks
>>>
>>

-- 





[web2py] Re: Add button to form & access from view

2012-12-11 Thread Daniele
Ok. What's the correct way of associating an action to the HTML button with 
web2py?

On Tuesday, December 11, 2012 12:30:34 AM UTC, Massimo Di Pierro wrote:
>
> This is not worth it. If you make a custom form than you are using html, 
> you may as well make the button in html.
>
> On Monday, 10 December 2012 15:15:30 UTC-6, Daniele wrote:
>>
>> When I use form.add_button() I am able to add a button to a form, which I 
>> can display with {{=form}} in my view.
>>
>> However, if I'm making a custom form using form.custom, how can I display 
>> that button??
>>
>> Thanks
>>
>

-- 





[web2py] Re: Add button to form & access from view

2012-12-10 Thread Massimo Di Pierro
This is not worth it. If you make a custom form than you are using html, 
you may as well make the button in html.

On Monday, 10 December 2012 15:15:30 UTC-6, Daniele wrote:
>
> When I use form.add_button() I am able to add a button to a form, which I 
> can display with {{=form}} in my view.
>
> However, if I'm making a custom form using form.custom, how can I display 
> that button??
>
> Thanks
>

--