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>
Related
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
i have this page that has two buttons divided By two clo-md-6 :
i want when i click in the button the first button become col-md-9 and the other col-md-3 and the same for the inverse
i don t know how to do it in angular
This is my HTML :
<div class="container-fluid">
<div class="row">
<!-- $("#btn1").parentElement.parentElement.className= "col-3"-->
<!--------------------THE FIRST BUTTON----------------------------->
<div class="col-xl-6" [class.col-xl-9]="isclicked">
<div class="card">
<button type="button" id="btn1" class="btn btn-primary" (click)="AfficherRecherche()">Agent professionnelle</button>
<div class="card-body" *ngIf="isclicked">
<h4 class="header-title mt-0 mb-4">Agent Professionnelle</h4>
<aw-wizard>
<aw-wizard-step class="sw-main sw-theme-default">
<form [formGroup]="searchForm">
<div class="row">
<div class="col-12">
<div class="form-group row mb-3">
<input type="text" class="form-control" (keyup)="searchTerm.next($event)" formControlName="search" placeholder="Rechercher ..." (input)="search()" [(ngModel)]="searchText" />
<div *ngIf="loading">
<p class="search-message">Searching</p>
<div class="lds-ellipsis">
<!-- -------------------------------THE SEOND BUTTON------------------------------------------------------------------ -->
<div class="col-xl-6" [class.col-xl-3]="isclicked">
<div class="card">
<div class="btn-group">
<button id="btn2" type="button" class="btn btn-primary" (click)="AfficherAgentpar()">Agent Partculier</button>
</div>
this is my component :
AfficherRecherche() {
this.isclicked = !this.isclicked;
}
AfficherAgentpar() {
this.agentparclick = !this.agentparclick;
}
You should trigger classes on click. So for example:
In your TS file declare a variable with a boolean:
public resize: boolean;
In your HTML you have 2 divs and a button:
<div class="clo-md-6" [class.col-md-9]="resize"></div>
<div class="clo-md-6" [class.col-md-3]="resize"></div>
<button (click)="resize != resize">Trigger me</button>
What happens is the following: When the button gets clicked it changes the value of our resize boolean. Since this is false by default, it'll trigger to true. When resize is true, the first div will be assigned the col-md-9 class, and the second div will be assigned the col-md-3 class. If you click the button again, the divs will go back to being 50/50.
I can not order my different div as I wish.
First, I would like the card to be the same height as my title.
Then, I want the bottom of my 2 buttons are at the same height as the bottom of my card.
I guess this is possible but I'm stuck ... Could you help me?
<div class="container" style="width:auto;margin-top:0%">
<div class="row col-12">
<div class="5" style="margin-top:2%"><h3>Change your user profile</h3></div>
<div class="card border-primary md-5 col-6" style="width: auto; margin-left:51%">
<div class="card-header" style="font-size:22px">Attention</div>
<div class="card-body">
<p class="card-text">
The modified data must first be validated. <br /><br />
A request will be sent as soon as you click on "Submit". <br /><br />
It is normal that the old data is still displayed, it means that the validation has not been done yet.
</p>
</div>
</div>
<div>
<button type="button" class="btn btn-outline-primary" id="btnMember" onclick="hideCPY()">Personnal</button>
<button type="button" style="margin-left:1%" class="btn btn-outline-primary" id="btnShowCompany" onclick="hideMember()">Company</button>
</div>
</div>
[
You should remove the margin-left:51% given to your card as you do not need margins when working with bootstrap grid. Also, you should move the buttons into the same first column container in order to align them along with the title.
<div class="container" style="width:auto;margin-top:0%">
<div class="row col-12">
<div class="col-5" style="margin-top:2%">
<h3>Change your user profile</h3>
<div>
<button type="button" class="btn btn-outline-primary" id="btnMember" onclick="hideCPY()">Personnal</button>
<button type="button" style="margin-left:1%" class="btn btn-outline-primary" id="btnShowCompany" onclick="hideMember()">Company</button>
</div>
</div>
<div class="card border-primary md-5 col-6" style="width: auto;">
<div class="card-header" style="font-size:22px">Attention</div>
<div class="card-body">
<p class="card-text">
The modified data must first be validated. <br /><br />
A request will be sent as soon as you click on "Submit". <br /><br />
It is normal that the old data is still displayed, it means that the validation has not been done yet.
</p>
</div>
</div>
</div>
Also, I would highly recommend removing inline styles and using CSS classes instead.
Working fiddle here: http://jsfiddle.net/omxahu46/
Hope this helps.
I have a basic btn-block btn-sm button in bootstrap that is at a fixed position using position:sticky; top:10px in my CSS. The problem is, the button doesn't show any hover effects, and you can't click on it, when the cursor is on the top half of the button. In addition, for a little but below the button, you can hover over it and the button shows hover effects, and when you click on it, a button click event is registered. It looks like the "clickable" portion of the button is offset by about 10px.
My other button(the Send button) doesn't seem to have this issue, so it looks like it has to do with the position sticky styling for that button.
Nobody else seems to have asked any questions similar to this, so I don't really even know how to get started with trying to find a solution.
Some of my code:
#latest-msg {
position: sticky;
top: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card" id="chat-wrapper">
<div class="card-header text-left" id="chat-title">
Chat
</div>
<div class="card-body" id="chat-messages">
<button type="button" class="btn btn-primary btn-block btn-sm" id="latest-msg">Latest Message</button>
<!--^^^THIS BUTTON-->
<p id="no-msg" class="text-muted">No Messages Yet. Be the first!</p>
<!--Some text is appended here via javascript.-->
</div>
<div class="card-footer text-muted text-right hidden " id="footer-send">
<label for="name">Name:</label>
<input class="form-control" placeholder="Message..." id="name">
<button class="btn btn-primary btn-block" id="name-enter">Send</button>
</div>
<div class="card-footer text-muted text-right" id="footer-name">
<textarea class="form-control" placeholder="Message..." id="chat-msg-box"></textarea>
<button class="btn btn-primary btn-block" id="msg-send">Send</button>
</div>
</div>
Adding this to a javascript file shows that the button does get clicked.
You can also check it out here: https://codepen.io/anon/pen/bazLvp
document.getElementById('latest-msg').addEventListener('click', buttonClicked);
function buttonClicked() {
console.log('the button was clicked');
}
I want to make the Submit button's length same as the input field above it.
<div class="row">
<div class="input-field col s12">
<input id="speciality" type="text" class="validate">
<label for="speciality">Speciality</label>
</div>
</div>
<div class="row">
<button class="btn waves-effect waves-light" type="submit" name="action">Search
<i class="material-icons right">search</i>
</button>
</div>
If your column which you have your input field in is limited to a certain width (in the way how the Bootstrap columns work), you can put the .btn inside a column as well.
After that, you can use the following CSS to make the width equal to the input field:
.col.s12 > .btn {
width: 100%;
}
Of course if the button as an element does not bend to this CSS-rule, you can use <a class="btn"> instead.
Surround the button with a div with col s12 classes and add btn-block to the button:
<div class="row">
<div class="col s12">
<button class="btn btn-block waves-effect waves-light" type="submit" name="action">Search
<i class="material-icons">search</i>
</button>
</div>
</div>
And add the following CSS:
.btn-block {
width: 100%;
}