Show sqlform when button is clicked

34 views
Skip to first unread message

Mujeeb Farees

unread,
Sep 20, 2017, 8:06:21 AM9/20/17
to web2py-users
The code is as follows,

Controller
def index():
    form
= SQLFORM(
           db
.home,
           submit_button
= 'Save'
       
)


View
<div>
   
<h5 class="title">Home</h5>
   
<button type="button">Add Home</button>
    {{=form}}
</div>    

I want to make the form visible only when "Add Home" button is clicked. Any suggestions?

Leonel Câmara

unread,
Sep 20, 2017, 8:38:22 AM9/20/17
to web2py-users
Use bootstrap collapse.

Mujeeb Farees

unread,
Sep 21, 2017, 3:08:27 AM9/21/17
to web2py-users
I used JQuery instead and did the following,

View
<div class="content">
   
<div id="chooseHome">

       
<h5 class="title">Home</h5>

       
<button onclick="displayHomeForm()">Add Home</button>
   
</div>
    {{=form}}
               
</div>

<script>
    $
( document ).ready(function() {
        $
('form').hide();
   
});

   
function displayHomeForm()
   
{
        $
('#chooseHome').hide();
        $
('#chooseHome').next().show();
   
}
</script>

Reply all
Reply to author
Forward
0 new messages