Skip to Content
Menu
This question has been flagged
5 Replies
7446 Views

I have a button "Add attribute".On clicking I want to hide other fields by calling a javascript function ..

How to implement that

I have inclided a template like this for calling javascript


       <template id="web_assets_frontend" name="website_variant_assets" inherit_id="website.assets_frontend">
         <xpath expr="//script[last()]" position="after">
              <script type="text/javascript" src="/website_variants/static/src/js/website_variant.js"></script>   
         </xpath>
       </template>

My button is this:

<input type="button" onclick="myfunction()"
            class="btn btn-primary" value="Add Attribute"
            style="margin:10px 0 0 0"></input>

myfunction is the javascript function which I have to call

Now my myfunction is this:-

function myfunction()
    {
        var y = document.getElementById("hide_button");
        if (y.style.display === "none")
            {
                y.style.display = "block";
            }
        else
            {
            y.style.display = "none";
            }
    }

How to implement this myfunction in odoo12

Please Help..

Thanks in Advance

           

Avatar
Discard

First of all you need to define button like this : -

<button class="btn btn-primary" id="button_id" t-attf-style="width:193px;height:50px;">Add Attribute</button>

Use this below code of js :-

self.$('#button_id').click(function (e){

// Find the element and do the whatever you want.

self.$('#hide_button').css('display','none');

self.$('#hide_button').css('display','block');

});

Author Best Answer

I got it..

odoo.define('website_variants.website_variant', function (require) {
 "use strict";
$(document).ready(function() {
 $('#button_id').click(function (e){

 var x = document.getElementById("hidden_box");
            if (x.style.display === "none") {
                x.style.display = "block";
                    } else {
                        x.style.display = "none";
                    }
});

});

});


Avatar
Discard
Best Answer

First of all you need to define button like this : -


<button class="btn btn-primary"  id="button_id" t-attf-style="width:193px;height:50px;">Add Attribute</button>


Use this below code of js :-

self.$('#button_id').click(function (e){

                // Find the element and do the whatever you want.

                self.$('#hide_button').css('display','none');

                self.$('#hide_button').css('display','block');

});

Avatar
Discard
Author

It doesnt work fo me

odoo.define('website_variants.website_variant', function (require) {

"use strict";

self.$('#button_id').click(function (e){

// Find the element and do the whatever you want.

self.$('#hide_button').css('display','none');

self.$('#hide_button').css('display','block');

});

});

And my button is:-

<button class="btn btn-primary" id="button_id" t-attf-style="width:193px;height:50px;">Add Attribute</button>

Than I think you missed something else because from myend their is perfect to me.