How to open Bootstrap v5 Offcanvas using switches? - html

I want to open the Bootstrap V5 Offcanvas using Bootstrap switches
the trick is simple when the input field is checked the Offcanvas should be opened and when Offcanvas is closed the checked should be removed.
My Code :
<!-- I want to Use checkbox switches to open the offcanvas -->
<div class="form-check form-switch">
<input type="checkbox" id="offcanvas-toggler" class="form-check-input" />
</div>
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasExample" aria-controls="offcanvasExample">
Button with data-bs-target
</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasExampleLabel">Offcanvas</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
</div>
</div>
</div>
references :
https://getbootstrap.com/docs/5.0/forms/checks-radios/
https://getbootstrap.com/docs/5.0/components/offcanvas/

You can do something like this..
var toggle = document.getElementById("offcanvas-toggler")
var offcanvas = new bootstrap.Offcanvas(document.getElementById("offcanvasExample"), {backdrop: false})
toggle.addEventListener("change", function(){
toggle.checked ? offcanvas.show() : offcanvas.hide()
})
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css">
<!-- I want to Use checkbox switches to open the offcanvas -->
<div class="form-check form-switch">
<input type="checkbox" id="offcanvas-toggler" class="form-check-input" />
</div>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasExampleLabel">Offcanvas</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script>
Demo

Related

How to align buttons vertically exactly undereach other

I have some buttons "the ones with information icon, and I want to align them so that to be arranged under each other vertically
image_1 shown the current alignment of the buttons.
Please let me know how to achieve aligning them vertically under each other using CSS and HTML
I thought of setting an equal margin to the left side starting from the check-box but I do not know how to do it
HTML markup:
<button class="btn btn-sm btn-icon" (click)="showInformation('SERVICE_SYNOPS_AGGREGATED_AREAS')">
<clr-icon shape="help-info" class="is-solid"></clr-icon>
</button>
<button class="btn btn-sm btn-icon" (click)="showInformation('SERVICE_SYNOPS_AGRICULTURAÖ_AREAS')">
<clr-icon shape="help-info" class="is-solid"></clr-icon>
</button>
<button class="btn btn-sm btn-icon" (click)="showInformation('SERVICE_SYNOPS_WATER_AREAS')">
<clr-icon shape="help-info" class="is-solid"></clr-icon>
</button>
img_1:
You can use Bootstrap classes such as row and column. So the layout would like this.
Read more about Bootstrap Grid system
<div>
<div class="row">
<div class="col-2">
<input type="checkbox" />
</div>
<div class="col-8">
Aggregated Areas
</div>
<div class="col-2">
<span style="border: 1px solid lightgreen">i</span>
</div>
</div>
<div class="row">
<div class="col-2">
<input type="checkbox" />
</div>
<div class="col-8">
Aggregated Areas
</div>
<div class="col-2">
<span style="border: 1px solid lightgreen">i</span>
</div>
</div>
<div class="row">
<div class="col-2">
<input type="checkbox" />
</div>
<div class="col-8">
Aggregated Areas
</div>
<div class="col-2">
<span style="border: 1px solid lightgreen">i</span>
</div>
</div>
</div>
<link rel="stylesheet" type="text/css"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js">
</script>
From the image I assume the box has a fixed width. You can use this as your limit and add an inline span between the text and the button and set it's width to fill the remaining available space. That should push the buttons to the right side.

Bootstrap Popover not working inside bootstrap panel body

I am having a simple bootstrap popover and I have placed it inside panel body. It works great when I place popover outside the panel body. But I am not sure why it is not working when I place same popover inside panel body.
PopOver Inside Panel Body
<div class="row">
<div class="col-md-12">
<div style="border:1px solid black; margin-top:5px; margin-bottom:5px;">
<input id="rbtnTab1" type="radio" name="tabs" checked>
<label id="lblTab1" for="rbtnTab1">Tab 1</label>
<section id="content1">
<div>
<div class="col-xs-4 col-md-offset-4">
<div class="panel panel-default" style="margin-top:10px">
<div class="panel-heading text-center" style="font-size:15px;font-weight:bold; background-color:#4D94CE; color:white;"><i class="fa fa-users" style="font-size:x-large"></i><br />Panel Heading</div>
<div class="panel-body text-center" style="height:60px;font-size:15px">
<button type="button" class="btn btn-info" data-toggle="popover" title="Popover title" data-content="A larger popover to demonstrate the max-width of the Bootstrap popover.">Large popover</button>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-info" data-toggle="popover" title="Popover title" data-content="A larger popover to demonstrate the max-width of the Bootstrap popover.">Large popover</button>
</section>
</div>
</div>
</div>
JQuery code for bootstrap popover
$('[data-toggle="popover"]').popover({
placement: 'top',
trigger: 'hover'
});
Popover outside the panel (This works great)
<button type="button" class="btn btn-info" data-toggle="popover" title="Popover title" data-content="A larger popover to demonstrate the max-width of the Bootstrap popover.">Large popover</button>

Reactive Forms, trigger three click events uniquely.1.To submit form 2.To send data from dropdown 3. Same as two, in same Reactive Form

I have written a Reactive form. The submit button is supposed to be outside the Reactive form.It has also got two dropdowns. In this form im reading data dynamically from api. I have written click events in the dropdown as well(for a purpose to bind that particular value when i submit the form). The issue here is that whenever i click on the dropdown...the submit button click event is getting triggered....i have been trying to make them(the three click events) be unique...but im unable to.... kindly help me. Below im providing my code.
<div class="container content-box-shadow tiles-top-spacing tiles-page">
<div class="row assessment-m-b">
<div class="col-lg-12 col-md-12 pt-3 pb-5">
<div class="d-flex align-items-center justify-content-between">
<span class="common-headding">{{pageText?.accountSettingPageTextData?.editHeader}}</span>
<div>
<button type="submit" class="common-button green"
(click)="onSubmit()">{{pageText?.accountSettingPageTextData?.save}}</button>
<button type="button"
class="common-button orange" (click)="previousModule()">{{pageText?.accountSettingPageTextData?.cancel}}</button>
</div>
</div>
<div class="account-settings-block">
<form *ngIf="personalData" [formGroup]="accountSettingsForm" >..................................................
<!-- Account-Settings Security Questions -->
<div *ngIf=" personalData?.dashBoardPersonalInfoData?.securityQuestionsAnswers.isVisible"
class="account-form-inner-block">
<legend>{{pageText?.accountSettingPageTextData?.questions?.header}}<span class="required">**</span></legend>
<div class="row">
<div class="col-md-6">
<div>
<label for="question1">
{{pageText?.accountSettingPageTextData?.questions?.question1}}
</label>
<div class="btn-group w-100 pt-1" ngbDropdown>
<button class="btn btn-secondary dropdown-toggle w-100 text-left"
aria-haspopup="true" aria-expanded="false" id="dropdownMenu1"
ngbDropdownToggle>
<span *ngIf="!SecurityQuestion1.question">
Select a Question
</span>
<span *ngIf="SecurityQuestion1.question">
{{SecurityQuestion1.question}}
</span>
</button>
<div class="dropdown-menu dropdown-menu-left" aria-labelledby="dropdownMenu">
<button (click)="selectQuestion1(questions)"
*ngFor="let questions of personalData?.dashBoardPersonalInfoData?.securityQuestions"
class="dropdown-item">{{questions?.question}}
</button>
</div>
</div>
</div>
<div>
</div>
</div>
</div>
<div class="col-md-6">
<div>
<label for="question2">
{{pageText?.accountSettingPageTextData?.questions?.question2}}
</label>
<div class="btn-group w-100 pt-1" ngbDropdown>
<button class="btn btn-secondary dropdown-toggle w-100 text-left"
aria-haspopup="true" aria-expanded="false" id="dropdownMenu2"
ngbDropdownToggle>
<span *ngIf="!SecurityQuestion2.question">
Select a Question
</span>
<span *ngIf="SecurityQuestion2.question">
{{SecurityQuestion2.question}}
</span>
</button>
<div class="dropdown-menu dropdown-menu-left" aria-labelledby="dropdownMenu">
<button (click)="selectQuestion2(questions)"
*ngFor="let questions of personalData?.dashBoardPersonalInfoData?.securityQuestions"
class="dropdown-item">{{questions?.question}}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
I could solve my issue above by using form="myForm" attribute in the save button. and using id="myForm" attribute in the form tag.....just by using those attributes....i could have unique trigger for all the three events......Im stilll keeping posted so that someone neednot have to waste almost 4hours or more in finding it out....

Is there any way to make each div collapse separately?

A button is created for each question from the database, when clicked, only one answer should be opened. But instead, when you click on any of the buttons, all answers open.
So far I've tried to change "collapse" to "${question.id}", but it seems to me that it doesn't work this way.
<div class="card-columns">
<#list questions as question>
<div class="card border-light mb-3 bg-card">
<div class="m-2">
<p>
<button class="btn btn-info" type="button"
data-toggle="collapse"
data-target="#collapse"
aria-expanded="false"
aria-controls="collapse">
${question.question}
</button>
</p>
</div>
<div class="m-2">
<div class="collapse" id="collapse">
<div class="card card-body border-info">
${question.answer}
</div>
</div>
</div>
<#else>
There is no questions.
</#list>
</div>
</div>
You need to change "collapse" to $question.id in 2 line:
<button ... data-target="#collapse"
and
<div ... id="collapse">(id not class).
I dont familiar with freemarker, so cant provide full fix.

Grouped bootstrap radio buttons as btn-primary buttons in different columns

I have problems with the layout of two grouped buttons, which are in the same group but in different columns. The buttons are supposed to be radio buttons in the style of simple btn btn-primary bootstrap buttons.
The first problem is that the actual radio button is displayed in the btn-primary button. When clicking the btn-primary button, it works just fine. But if I happen to check the radio button inside the btn-primary button, the btn-primary button will appear checked, but actually isn't (the radio button isn't checked).
The second problem I tried to solve is to make the radio button inside the button disappear. But I can't seem to find a solution that works with button grouping inside different columns.
Here's a picture of the modal dialog with the stated buttons. You can see the second btn-primary button appearing checked, even though the left "Type 1" button is actually checked.
HTML:
<div class="container">
<h3>{{ 'ADDGROUP_MODEL' | translate }}</h3>
<div class="row">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<div class="column"><img class="img" src="http://via.placeholder.com/172x200" align="middle"><label class="btn btn-primary active"><input type="radio" id="radioAddModel1" name="groupModelRadio" autocomplete="off">{{
'ADDGROUP_CHOOSEMODEL1' | translate }}</label> </div>
<div class="column"><img class="img" src="http://via.placeholder.com/172x200" align="middle"><label class="btn btn-primary"><input type="radio" id="radioAddModel2" name="groupModelRadio" autocomplete="off">{{
'ADDGROUP_CHOOSEMODEL2' | translate }}</label> </div>
</div>
</div>
</div>
Every help is highly appreciated,
thanks in advance,
a.j.stu
There are many ways to achieve what you want. If followed by your approach of using radio buttons, you should make use of ng-model on radio buttons & hide them with visibility: hidden property. And then you can make use of angular's ng-class to have style on label buttons when particular selected.. You can have template like:
<label class="btn btn-primary" ng-class="{'selected': radioAddModel === '1'}">
<input type="radio" id="radioAddModel1" ng-model="radioAddModel" name="groupModelRadio"
value="1" autocomplete="off" class="hide">{{'ADDGROUP_CHOOSEMODEL1' | translate }}
</label>
<label class="btn btn-primary" ng-class="{'selected': radioAddModel === '2'}">
<input type="radio" id="radioAddModel2" ng-model="radioAddModel" name="groupModelRadio"
value"2" autocomplete="off" class="hide">{{'ADDGROUP_CHOOSEMODEL2' | translate }}
</label>
where classes can be:
.hide {visibility: hidden; }
.selected { background: green; }
Now whenever user clicks on button that radio button will be checked and model value will be updated & accordingly buttons will be styled.
Demo plunker Example
This is overkill, but here is a BS4 Card Deck with a "distributed" radio button group. You may need to be more specific with the selectors to make sure you isolate only the buttons you need.
Be mindful of the Bootstrap CSS override, and note the jquery.
$(function() {
$('label.btn').click(function() {
var $rb = $(this).find("input[type=radio]").prop('checked',true);
$('#log').text("Selected " + $("input[type=radio]:checked").attr('id') );
});
});
/* Overide Bootstrap's default styling that uses the child selector
.btn-group-toggle>.btn input[type=radio]
*/
.btn-group-toggle .btn input[type=radio] {
position: absolute;
clip: rect(0, 0, 0, 0);
pointer-events: none;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<div id="log">
</div>
<div class="container">
<div class="row">
<div class="col-8">
<div class="btn-group-toggle" data-toggle="buttons">
<div class="card-deck">
<div class="card">
<img class="card-img-top" src="https://picsum.photos/100/80" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a card </p>
<label class="btn btn-primary">
<input type="radio" name="ItemList" id="rblItem1" autocomplete="off">Item 1
</label>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
<div class="card">
<img class="card-img-top" src="https://picsum.photos/100/80" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is another card.</p>
<label class="btn btn-primary">
<input type="radio" name="ItemList" id="rblItem2" autocomplete="off">Item 2
</label>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
</div>
</div>
</div>
</div>
</div>