"Implementing a toggle switch on your Odoo website the right way: a step-by

I am looking to implement a toggle switch in the header of my Odoo template. I came across this Bootstrap code snippet:

<div class="custom-control custom-switch">
  <input type="checkbox" class="custom-control-input" id="customSwitch1">
  <label class="custom-control-label" for="customSwitch1">Toggle this switch element</label>
</div>

The toggle switch works fine on laptops, but disappears when viewed on a tablet.

On Laptop : view image here

On Tablet : view image here

I haven't applied any CSS. Can anyone explain why the header vanishes on tablets?

Tested with Google Chrome on Samsung Galaxy TAB lite tablet, running Android version 4.4.4

I also tried using a different toggle switch code, but encountered the same issue.

The problem persists when tested on an iPad as well.

Here is the complete code:

<div id="top_menu_collapse" class="collapse navbar-collapse ml-lg-3">
                    <t t-call="website.navbar_nav">
                        <t t-set="_nav_class" t-valuef="flex-grow-1"/>
                        <!-- Menu -->
                        <t t-foreach="website.menu_id.child_id" t-as="submenu">
                            <t t-call="website.submenu">
                                <t t-set="item_class" t-valuef="nav-item"/>
                                <t t-set="link_class" t-valuef="nav-link"/></t>
                        </t>
                        <!--Toggle Swith-->
                        <span style="margin-top: -15px; margin-left: 10px" >
                            <center>
                                <b>Prix</b>
                            </center>
                            <div class="custom-control custom-switch">
                                <input type="checkbox" class="custom-control-input" id="customSwitch1"/>
                                <label id="custom-switch-on-off" class="custom-control-label" for="customSwitch1"></label>
                            </div>
                        </span>
                        <!-- Sign In -->
                        <t t-call="portal.placeholder_user_sign_in">
                            <t t-set="_item_class" t-valuef="nav-item ml-lg-auto"/>
                            <t t-set="_link_class" t-valuef="nav-link"/></t>
                        <!-- User Dropdown -->
                        <t t-call="portal.user_dropdown">
                            <t t-set="_user_name" t-value="True"/>
                            <t t-set="_user_name_class" t-valuef="font-weight-bold"/>
                            <t t-set="_item_class" t-valuef="nav-item dropdown ml-lg-auto"/>
                            <t t-set="_link_class" t-valuef="nav-link"/></t>
                    </t>
                    
                    <!-- Language Selector -->
                    <t t-call="website.placeholder_header_language_selector">
                        <t t-set="_div_classes" t-valuef="my-auto ml-lg-2 align-self-lg-center"/></t>
                    <!-- Call To Action -->
                    <t t-call="website.placeholder_header_call_to_action">
                        <t t-set="_div_classes" t-valuef="d-none d-lg-block ml-3"/></t>
                </div>

Answer №1

To expand the functionality, consider moving the toggle switch outside of the navbar_nav element. Here is an example:

<div id="top_menu_collapse" class="collapse navbar-collapse ml-lg-3">
    <t t-call="website.navbar_nav">
        <t t-set="_nav_class" t-valuef="flex-grow-1"/&>
        <!-- Menu -->
        <t t-foreach="website.menu_id.child_id" t-as="submenu">
            <t t-call="website.submenu">
                <t t-set="item_class" t-valuef="nav-item"/>
                <t t-set="link_class" t-valuef="nav-link"/>
            </t>
        </t>
        <!-- Sign In -->
        <t t-call="portal.placeholder_user_sign_in">
            <t t-set="_item_class" t-valuef="nav-item ml-lg-auto"/>
            <t t-set="_link_class" t-valuef="nav-link"/>
        </t>
        <!-- User Dropdown -->
        <t t-call="portal.user_dropdown">
            <t t-set="_user_name" t-value="True"/>
            <t t-set="_user_name_class" t-valuef="font-weight-bold"/>
            <t t-set="_item_class" t-valuef="nav-item dropdown ml-lg-auto"/>
            <t t-set="_link_class" t-valuef="nav-link"/>
        </t>
    </t>
</div>
<!--Toggle Swith-->
<span style="margin-top: -15px; margin-left: 10px">
    <center>
        <b>Prix</b>
    </center>
    <div class="custom-control custom-switch">
        <input type="checkbox" class="custom-control-input" id="customSwitch1"/>
        <label id="custom-switch-on-off" class="custom-control-label" for="customSwitch1"></label>
    </div>
</span>
<!-- Language Selector -->
<t t-call="website.placeholder_header_language_selector">
    <t t-set="_div_classes" t-valuef="my-auto ml-lg-2 align-self-lg-center"/>
</t>
<!-- Call To Action -->
<t t-call="website.placeholder_header_call_to_action">
    <t t-set="_div_classes" t-valuef="d-none d-lg-block ml-3"/>
</t>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I correctly focus on 'highlight' events using the tab key on an HTML element?

I'm struggling to figure out the event that is triggered when an element gains focus through tab navigation. I want all buttons in the codepen provided to expand to full size when tabbed over. https://codepen.io/anon/pen/YopBaz Currently, I have achi ...

jQuery cannot access a hidden CSS property

I'm working on a form for my new project and have assigned the same class to all input fields. In my CSS file, I've set the text to be capitalized and it displays correctly. However, when I use jQuery's .val() to get the value of the field, ...

How can I create a dynamic height for a scrollable div?

How can I build a section with a defined height that contains a sticky header (with a dynamic height) and a scrollable body? I want the body to be scrollable, but due to the header's changing height, I'm unable to set an exact height. What should ...

What is the best way to retrieve the data-id from a button that has been appended?

JavaScript $("#btn").on('click', function(){ $("#result").append("<button type='button' id='btnid' data-id='show' //want to retrieve this class='close pull-right' aria-hidden='true&apos ...

Changing Location of Carousel in Bootstrap

Recently, I have been working with Bootstrap and have encountered a problem with the carousel. I have placed carousel images below my navbar, but there seems to be a gap between the navbar and the carousel image. I want the image to be right below the navb ...

eliminate the script and HTML comment from a designated division

Here is the default code that I need to modify using JavaScript to remove scripts, comments, and some text specifically from this div: I came across this script that removes all scripts, but I only want to remove specific ones from this div: $('scri ...

What is the best way to continuously loop an image from left to right and right to left indefinitely using JavaScript?

As part of the challenge, I am tasked with creating a Pacman game using HTML, CSS, and JavaScript. One key aspect is to control the movement of the ghosts throughout the game. However, I am facing an issue with the current function that controls the ghost& ...

Ensuring that the empty bubble remains undisturbed, here's a guide on effectively implementing the if

I need assistance with adding an "if condition" to my text field. The condition should prevent the empty bubble from appearing when the send button is clicked. function verifyInput(){ var currentText = document.getElementById("demo").innerHTML; var x ...

Placing the date of each blog post at the end of the excerpt

Currently, there is a grid section on the homepage of our site showcasing the two most recent blog posts. I am looking for a Javascript solution to relocate the date to the bottom of each block, outside of the border. For reference, you can visit the follo ...

Adjusting the angular routerLink based on an observable

When working with HTML in Angular, I am looking for a way to use an <a> tag that adjusts its routerlink based on whether or not a user is logged in. Is it possible to achieve this functionality within a single tag? <a *ngIf="!(accountService ...

Difficulty encountered in aligning items within neighboring table cells vertically

Currently, I am facing a styling issue with a few table rows. In this particular screenshot: https://i.sstatic.net/FcmJW.png The cells in the blue and red circles are part of a table row (with a height of 50px). Both are set to "vertical-align:top". The ...

What is preventing my JavaScript from loading on my website when using window.onload?

I'm currently in the process of building an HTML page with Adobe Dreamweaver and utilizing the Live Preview feature to preview the page on a local server. However, I am facing some issues with my JavaScript code. I am attempting to populate a dropdown ...

Is it feasible to transition a mobile webpage seamlessly without using jqm?

I'm currently developing a Phonegap app and I am trying to steer clear of jqm in my project. I find that the css is causing some issues with the html code. As a workaround, I can transition between pages using: window.location = "profiles.html"; How ...

Tips for toggling the appearance of like and add to cart icons

I am attempting to create a simple functionality for liking and adding items to a cart by clicking on the icons, which should immediately change the icon's color when clicked. However, I am facing an issue where the parent div's link is also bein ...

Ways to showcase INPUT TYPE when making a Selection?

I've been struggling with a simple issue and despite trying multiple solutions, I can't seem to get it right. I have a form where I'm using the <select> tag with two options: coo and uh. What I want is for an additional input type fiel ...

Error: The database connection is currently down

Hey there! I'm currently working on a school project and running into some issues with inserting data into the database. I can't figure out what I'm doing wrong. There are no errors showing up, but for some reason, the information I input i ...

Unable to append new select options to a current selection field on Odoo 15

i have defined two selection fields x = fields.Selection([('x A','x A'),('x B','x B')],string='X') y = fields.Selection([('0','0')],string='Y') then i attempted to include s ...

Having trouble initiating an AJAX call in Django and returning values to my form

Seeking assistance to run an AJAX call for a quick calculation in my django view and display the result within a span tag on my HTML page. New to Javascript, struggling with triggering my AJAX call. Below is my HTML and JS code: <input type="text" nam ...

Implementation of internationalization into a JSON-formatted data file

I recently integrated i18n into my application and I'm facing a challenge with implementing the useTranslation(); function in my navbar data file. This file serves as the database for the page titles and tabs, and I'm unsure about how to proceed. ...

Shifting the div with a sliding animation!

My webpage features a video background with text overlay, and I am looking to add a button in the center of the page. When users click on this button, I want the current text div to slide up using a CSS transition, revealing another div with the same effec ...