Why does the design break when the div block is switched to visible?

In my Laravel 5 project with jQuery 3 and Bootstrap 4.4 integrated using Blade templates, there are certain blocks that are initially hidden.

<div class="form-row m-0 p-0" id="div_checking_step_2_recurring_rent" style="display: none; border: 2px dotted blue;">
    <label for="numeric_step_2_recurring_rent" class="col-12 col-sm-6 col-form-label" style="border: 2px dotted yellow;">Rent</label>
    <div class="col-12 col-sm-6">
        {!! $viewFuncs->text('numeric_step_2_recurring_rent', '', "form-control editable_field", ["maxlength"=>"255",
        "autocomplete"=>"off", "style"=>"border: 2px dotted green;" ] )      !!}
        <input type="text" id="step_2_recurring_rent" name="step_2_recurring_rent" value="0" style="visibility: hidden; width: 1px; height: 1px">
    </div>
</div>

These blocks only become visible when a user clicks on a checkbox. This functionality is achieved through the following method:

bookingsAndAvailability.prototype.is_recurringOnChange = function () {
    var is_recurring= $("#step_2_recurring_is_recurring:checked").val()
    if (is_recurring) {
        $("#div_checking_step_2_recurring_rent").css("display", "block")
    } else {
        $("#div_checking_step_2_recurring_rent").css("display", "none")
    }

}

The issue arises when the above method is triggered and 'div_checking_step_2_recurring_rent' becomes visible.

In this scenario, the label and div inside 'div_checking_step_2_recurring_rent' do not align on the same line; instead, the div appears below the label.

If the style "display: none;" 

is removed from the code as mentioned above, then the label and div align properly on the same line within 'div_checking_step_2_recurring_rent'.

I'm seeking assistance in identifying what could be missing in the 'bookingsAndAvailability.prototype.is_recurringOnChange' method?

Thank you!

Answer №1

It seems that in Bootstrap, the default setting is display: flex;. So, when you remove display: none;, it doesn't switch to display: block but remains as display: flex;. This explains why removing that code allows it to work.

When toggling with JavaScript, you should set it to flex instead of block. You can achieve this by using the following code:

bookingsAndAvailability.prototype.is_recurringOnChange = function () {
    var is_recurring= $("#step_2_recurring_is_recurring:checked").val()
    if (is_recurring) {
        $("#div_checking_step_2_recurring_rent").css("display", "flex")
    } else {
        $("#div_checking_step_2_recurring_rent").css("display", "none")
    }
}

I hope this explanation helps clarify things for you.

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

Make sure to confirm the input length and utilize bootstrap validation for error checking

I have a rather straightforward question. I am currently utilizing Bootstrap 4.6 and am looking to implement form validation for my input field. The requirement is to validate whether the input has a length of 5 characters or less, in which case it should ...

Using the symbols '&', '>', and '*' in the styling of React components

Below is the code snippet in question: const useStyles = makeStyles(theme => ({ row: { '& > *': { fontSize: 12, fontWeight: 'bold', color: 'rgba(33,34,34,0.5)', letterSpacing: 0.5, ...

Having Trouble with Navbar Toggler Functionality in Bootstrap 5

I'm currently working on a responsive webpage using Bootstrap 5, and I've encountered an issue with the Navbar. The toggle button isn't functioning properly – nothing happens when clicked. I've tried looking through the official docu ...

The issue arises when using Jquery version 3.4.1, where the ".on()" method for the "click" event does not trigger when the

Currently, I am learning Cordova through a tutorial that involves Jquery 3.4.1 and Bootstrap 4.4.1. The tutorial is a bit outdated, so before reaching out to the author, I figured I would seek help on this platform (link to tutorial: ) While I assume the ...

Updating borderWidth dynamically in react native fails to produce the desired effect

Here is the code I am working with: const [focused, setFocused] = useState(false); <TextInput style={{ ...styles.inputStyles, borderColor: `${focused ? colors.darkPurple : "#b8b8b850"}`, borderWidth: `${focused ? 3 : 1}`, }} placeh ...

Display the X button solely once text has been inputted into the textbox

I have integrated a text clearing plugin from here in my project to allow users to clear the input field by clicking on an X button. However, I want to modify the code so that the X button only appears when there is text entered in the textbox. I attempt ...

Menu Table displaying errors in layout

I've been struggling to align the menu table to match the homepage, but so far I haven't had any success. It seems like the main index.php page is using its own CSS for some unknown reason. Check out lcrisq.com Here is the desired design: Take ...

Ways to include scrolling specifically for one template

As a newcomer to frontend development, I have recently started learning Vue and the Quasar Framework. I am currently working on a table and trying to set a fixed table name with only the table items scrollable. <template> <q-table virt ...

How can I update the content of a span in Angular 2 by clicking a div, and then change the text above it when the span is filled?

As a newcomer to this community with basic English proficiency, I hope to communicate effectively. My journey into learning Angular 2 has led me to a specific question: I've set up a keyboard with four spans above it, each intended to hold a digit th ...

Can dynamic CSS imports be unloaded in a React application?

I am facing an issue with loading two files using react.lazy and suspense: import React, { Suspense, lazy } from "react"; import { Route, Redirect } from 'react-router-dom'; const MainLayout = lazy(() => import('Components/Layout/MainL ...

Responsive websites won't function properly

Hello all, I am currently working on centering my Navigation at screen sizes of 320 pixels or less. My goal is to have the logo centered at the top, followed by a centered navigation below, and then everything else aligned accordingly. However, I seem to b ...

What is the best way to incorporate CSS conditions within a function?

After creating a filter function in React to organize images by category, I encountered an issue where the filtered images weren't centered as I wanted them to be. I am now looking for a way to integrate centering into the filtering process so that wh ...

Implementing a pop-up notification at the center of the display for empty fields

I am currently working on a task that requires me to display a pop-up message at the top-middle of the screen stating "please fill in all fields before submitting". This custom box should be stylable using CSS. Although the solution seems simple, I am str ...

Only conceal the table column if space is limited

A scenario involves an HTML table with two columns that need to be displayed fully, with the second column aligned to the right. Currently, this has been achieved by setting the width of the first column to 100%. However, a challenge arises where the words ...

What is the best way to ensure a superfish dropdown menu is fully responsive?

Currently, I have implemented a superfish dropdown menu within the skelton framework. My goal is to make it functional on mobile devices as well. The issue I am facing is that by default, the dropdown items appear but they hover over the items below them ...

Arranging CSS text in a parallel format and aligning it vertically

I am working on a layout with two columns of text placed side by side, where one column is right aligned and the other is left aligned. Below is my current code: .alignleft { float: left; } .alignright { float: right; } .list-unstyled { padding ...

Guide on making a flowchart using CSS

I'm working on creating a CSS flow chart diagram and I've included an image below for reference. Might there be a straightforward method to achieve this? I've been scouring the web for examples, but I'm unsure of what terminology to use ...

Adjusting the size and appearance of ngDialog

Currently using the Ionic framework and encountering an issue with popup sizing. $scope.dialog = ngDialog.open( { template: 'popup.html' , className: 'ngdialog-theme-default' , controller: 'MyCtrl' ); By default, the popup o ...

Collection of pictures with the ability to magnify

I'm attempting to add a zoom feature to my gallery using HTML, CSS, and JavaScript, but I'm unsure of the precise steps. The end result I'm aiming for is similar to the effect seen at this link: ...

Incorporate a vertical scrollbar in the tbody while keeping the thead fixed for smooth vertical scrolling

I'm seeking a solution to implement horizontal and vertical scroll for my table. Currently, the horizontal scroll is working fine, but when trying to add vertical scroll, the table header also moves along with it. Is there a way to keep the table hea ...