daniel
daniel

Reputation: 43

web2py button with action and visual pudates

I have a view with a button and a DIV

I am trying to have this kind of functionality:

  1. if the button is clicked - a controller method is executed ( i have the method, db.insert, etc.) - if test (inside the controller method) is passed the button dissapears and the div appears ( I thought at using ajax - not to refresh the hole page)

  2. whenever the page is refreshed the test has to be made again for the button to be visible or not

thanks

Upvotes: 1

Views: 2701

Answers (2)

daniel
daniel

Reputation: 43

I looked in more of your examples and I think my problem was simpler ( if there isn't any other solution) So what I did was I used eval:

button in view :

<input id="b_normal" type="button" value="normal" onClick="ajax('{{=URL('db_test')}}',[],':eval')" />

and the controller method:

def db_test()

 #tests and updates
 return "jQuery('#b_normal').fadeOut();jQuery('#commDiv').show();"

for further refresh i used jquery, in view:

jQuery(document).ready(function(){

var flag = '{{=flag_normal}}';
if(flag == 'da')
    jQuery('#b_normal').hide();
else jQuery('#commDiv').hide();
});

where *flag_normal* is sent by the main controller

I hope this is not too inefficient and if so, useful

Upvotes: 0

Massimo
Massimo

Reputation: 1653

Something like this?

{{=DIV(A('click me',callback=URL('mycallback'),target="me"),_id="me")}}

def mycallback():
    # do whatever you need to do
    return DIV("I will appear in place of he link when you click")

Upvotes: 2

Related Questions