Search code examples
odooodoo-12

Check if user clicked the checkbox


On QWEB Invoice Portal I wanna check if user have checked the checkbox, if checked show the buttons else hide them.

I create a field on Invoice model: x_custom_checkbox: bool

Default state: False

When the state of x_custom_checkbox = False

enter image description here

When the state of x_custom_checkbox = True

enter image description here

On view Invoice Portal Template I use <input type="checkbox" id="invoice.x_custom_checkbox"/> to call the field, who can dynamically show/hide the 2 buttons (above image) according the state of checkbox?


Solution

  • My solution is actual very simple after some testings on Invoice Portal xml

     <center><input id="checkbox-status" type="checkbox" name="invoice.x_custom_checkbox"/> Accept</center>
    
     <div id="ShowHideDiv" class="o_download_pdf btn-toolbar flex-sm-nowrap">
    
        <script type="text/javascript">
                $("#ShowHideDiv").hide();
                $("#checkbox-status").change(function() {
                    if ( $(this).is(':checked') ) {
                        $("#ShowHideDiv").show();
                    } else {
                        $("#ShowHideDiv").hide();
                    }
                });