I used ngb dropdown to display the different statuses that my task can have ('to do', 'in progress', 'done'). Everything works fine, but there is one small issue that's still bothering me. After clicking one of the options I want the dropdown menu to close. At the moment it remains open. How can I close this menu when I click on it?
as you can see below I changed the status on two posts, but the dropdown menu remains open, which is not really something I want
Template code
<div class="col-md-4 text-right padding-topright" style=" object-fit: cover;">
<div ngbDropdown class="d-inline-block">
<button class="btn btn-sm kbn-todo" *ngIf="post.task.status == 'to do'" id="dropdownDone" style=" color: white;"
ngbDropdownToggle>{{post.task.status}}</button>
<button class="btn btn-sm kbn-working" *ngIf="post.task.status == 'in progress'" id="dropdownDone" style=" color: white;"
ngbDropdownToggle>{{post.task.status}}</button>
<button class="btn btn-sm kbn-done" *ngIf="post.task.status == 'done'" id="dropdownDone" style=" color: white;"
ngbDropdownToggle>{{post.task.status}}</button>
<div ngbDropdownMenu aria-labelledby="dropdownToDo">
<button class="dropdown-item pumpkin-orange-bg" (click)="OnMarkTaskToDo(i, this.post._id)">To Do</button>
<button class="dropdown-item" (click)="OnMarkTaskInProgress(i, this.post._id)">In Progress</button>
<button class="dropdown-item" (click)="OnMarkTaskCompleted(i, this.post._id)">Done</button>
</div>
</div>
<p class="small font-weight-bold" style="margin-top: 5px" *ngIf="post.task?.due_to != 'Invalid date'"> due {{post.task?.due_to | date}}</p>
<!-- <p class="small font-weight-bold" style="margin-top: 5px"> status- {{post.task?.status}}</p> -->
</div>
You can do something like this:
<div class="d-inline-block" ngbDropdown #myDrop="ngbDropdown">
<button class="btn btn-outline-primary mr-2" id="dropdownManual" ngbDropdownAnchor (focus)="myDrop.open()">Toggle dropdown</button>
<div ngbDropdownMenu aria-labelledby="dropdownManual">
<button ngbDropdownItem>Action - 1</button>
<button ngbDropdownItem>Another Action</button>
<button ngbDropdownItem>Something else is here</button>
</div>
</div>
<button class="btn btn-outline-danger mr-2" (click)="myDrop.close();">Close from outside</button>
Take a closer look on:
#myDrop="ngbDropdown"
And:
(click)="myDrop.close();"
I suppose there are many people which would like this solution.
This is an example taken from: https://ng-bootstrap.github.io/#/components/dropdown/examples
If you question is about CSS/HTML, you just need to apply something as display: none in your menu container.
But you you question is about Angular, you will need something like this:
showMenu: boolean = false;
closeMenu() {
let displayMenu = showMenu ? true : false;
return displayMenu;
}
<div class="menu-container" *ngIf="showMenu">
<button class="close-menu" (click)="closeMenu()"></button>
</div>
This process can be done in very different ways and everything it will depend how you want to work, with animation, with a global event to click "out" of the menu and then the menu disappears, and on...
Anyway I hope these examples can make your path more clear.
Related
Here I added 2 buttons on the header of the accordian, but when I click the button the entire accordian collapses or expands. Is there a way to add buttons to it in such a way that clicking them won't collapse or expand the accordion?
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseTwo" aria-expanded="false"
aria-controls="panelsStayOpen-collapseTwo">
<div>26-08-21</div>
<div style="margin-left: -20px;" class="col-1"></div>
<div>project_id</div>
<div class="col-3"></div>
<div>title</div>
<div class="col-3"></div>
</button>
<button type="button" class="btn btn-sm btn-success">
<em class="far fa-edit"></em> Edit
</button>
<button type="button" class="btn btn-sm btn-danger">
<i class="far fa-trash-alt"></i> Delete
</button>
</h2>
<div id="panelsStayOpen-collapseTwo" class="accordion-collapse collapse"
aria-labelledby="panelsStayOpen-headingTwo">
<div class="accordion-body">
<br>
<button style="margin-left: 20px;" type="button" class="btn btn-sm btn-outline-primary">Download CSV</button>
</div>
</div>
</div>
With the on click of buttons, you need to use $event.stopPropagation()
public onButtonClick($event): void {
// Do something on click
$event.stopPropagation()
}
I'm working on a data visualizer project. In this project users need to be able to make look ups to make it easy to find cretin data quickly. To do this I'm am using ngbDropdownMenu from NgBootstrap. They click a button and a little dropdown menu pops up so they can make a new look up.
When the menu pops up. They give a name and description to the new look up and hit submit. It will then create a new look up and fire an event I made so that I can close the dropdown menu NgbDropdownMenu.close();
HTML for the dropdown menu
<div ngbDropdown id="caseCodeDropdown"
(openChange)="openChange($event);"
class="input-group-append d-inline-block col-sm-1 px-0 mx-0">
<button ngbDropdownToggle class="btn btn-sm btn-outline" type="button" >
<i class="fal fa-plus"></i>
</button>
<div ngbDropdownMenu>
<newLookUpComponent></newLookUpComponent>
</div>
</div>
Component for dropdown menu
#ViewChild(NgbDropdownMenu) caseCodeDropdown: NgbDropdownMenu;
public dropdownCloseSub: Subscription = new Subscription;
constructor(private _eventEmitterService: EventEmitterService) { }
public ngOnInit(): void {
this.dropdownCloseSub = this._eventEmitterService.invokeSubmitNewMatterCode.subscribe(() => {
this.caseCodeDropdown.dropdown.close();
});
}
This works perfectly. The problem is when I need to have more than one dropdown menus on one page. I have five look ups for one of the pages and when I use the code below it only works for the caseCodeDropdown which is the first dropdown from the top of the html doc.
HTML with more than one dropdown menu
<div ngbDropdown id="caseCodeDropdown"
(openChange)="openChange($event);"
class="input-group-append d-inline-block col-sm-1 px-0 mx-0">
<button ngbDropdownToggle class="btn btn-sm btn-outline" type="button" >
<i class="fal fa-plus"></i>
</button>
<div ngbDropdownMenu>
<newLookUpComponent></newLookUpComponent>
</div>
</div>
<div ngbDropdown id="fileNoDropdown"
(openChange)="openChange($event);"
class="input-group-append d-inline-block col-sm-1 px-0 mx-0">
<button ngbDropdownToggle class="btn btn-sm btn-outline" type="button" >
<i class="fal fa-plus"></i>
</button>
<div ngbDropdownMenu>
<newLookUpComponent></newLookUpComponent>
</div>
</div>
<div ngbDropdown id="OPCDropdown"
(openChange)="openChange($event);"
class="input-group-append d-inline-block col-sm-1 px-0 mx-0">
<button ngbDropdownToggle class="btn btn-sm btn-outline" type="button" >
<i class="fal fa-plus"></i>
</button>
<div ngbDropdownMenu>
<newLookUpComponent></newLookUpComponent>
</div>
</div>
Component with more than one dropdown menu
#ViewChild(NgbDropdownMenu) caseCodeDropdown: NgbDropdownMenu;
#ViewChild(NgbDropdownMenu) fileNoDropdown: NgbDropdownMenu;
#ViewChild(NgbDropdownMenu) OPCDropdown: NgbDropdownMenu;
public dropdownCloseSub: Subscription = new Subscription;
constructor(private _eventEmitterService: EventEmitterService) { }
public ngOnInit(): void {
this.dropdownCloseSub = this._eventEmitterService.invokeSubmitNewMatterCode.subscribe(() => {
this.caseCodeDropdown.dropdown.close();
this.fileNoDropdown.dropdown.close();
this.OPCDropdown.dropdown.close();
});
}
WHAT I HAVE TRIED
First I tried
#ViewChild("caseCodeDropdown") caseCodeDropdown: NgbDropdownMenu;
#ViewChild("fileNoDropdown") fileNoDropdown: NgbDropdownMenu;
#ViewChild("OPCDropdown") OPCDropdown: NgbDropdownMenu;
Using #ViewChild() passing in the id of the element left all the caseCodeDropDown, fileNoDropdown, OPCDropdown as undefinded. I was unable to close them.
Next
var target = document.getElementId('caseCodeDropdown');
The problem with this method is I'm unable to use the ngbDropdownMenu functions. target.dropdown.close() throws an error.
Is there any other way I can get the element by its ID and still use the ngbDropdownMenu functions.
Thanks for your time!
So my goal is to make an dropdown with decrement/increment button like below.
https://imgur.com/A4zleSX
and these are my current codes
<div class="dropdown">
<button class="btn border-0 dropdown-toggle form-control" type="button"
id="dropdownMenu2" data-toggle="dropdown" aria-expanded="false">
Dropdown</button>
<div class="dropdown-menu" style="width: 250px; background-color: #343a40"
aria-labelledby="dropdownMenu2">
<div class="dropdown-item">
<div class="row text-white">
<div class="col-md">
<i class="fa fa-user mr-2"></i>Adult</div>
<div class="col-md text-center">
<button class="btn btn-sm btn-success mx-2">+</button>
<span>1</span>
<button class="btn btn-sm btn-success mx-2">+</button>
</div>
</div>
</div>
</div>
So i've managed to make till this point, but i have problems when the button is clicked inside the dropdown, it scrolls to page the top and i also don't like the background color changes when the dropdown item is hovered.
please help me to make it happen, thank you
UPDATE:
so all left is preventing the page to scroll when the button inside dropdown is clicked, can anyone help please?
Firstly you need to keep on dropdown when user click anything in it.
JS:
$('.keep-open').on({
"shown.bs.dropdown": function() { $(this).attr('closable', false); },
"click": function() { },
"hide.bs.dropdown": function() { return $(this).attr('closable') == 'true'; }
});
$('.keep-open #dLabel').on({
"click": function() {
$(this).parent().attr('closable', true );
}
})
html:
<div class="dropdown-menu" role="menu" aria-labelledby="dLabel" style="width: 250px; background-color: #343a40" >
<div style="display: block;text-align:center;margin-bottom:5px;margin-top:5px">
<div style="display: inline-block;color:white">
<i class="fa fa-user mr-2" style="margin:15px;"></i>Adult</div>
<button class="btn btn-sm btn-success mx-2">-</button>
<span>1</span>
<button class="btn btn-sm btn-success mx-2">+</button>
</div>
<div style="display: block;text-align:center;margin-bottom:5px;">
<div style="display: inline-block;color:white;">
<i class="fa fa-user mr-2" style="color:white;margin:15px;"></i>Child</div>
<button class="btn btn-sm btn-success mx-2">-</button>
<span>1</span>
<button class="btn btn-sm btn-success mx-2">+</button>
</div>
</div>
plunker: http://plnkr.co/edit/s4nmZVXpLMzZLDSzVd24?p=preview
I have the following code here:
<div class="container-fluid">
<div class="row-fluid">
<div class="centering col-lg-8 topSection" style="text-align: center;">
<div class="col-lg-12" style="padding-top: 160px;">
<h2 style="color: #fff; font-size: 30px;">Get discovered - Discover - Connect</h2>
<h3 style="color: #fff; font-size: 23px;">We love everyting about music. The scene. The people. The livestyle. We live for it.</h3>
<button type="submit" class="btn_style_1 btn" data-toggle="modal" data-target="#myModalLogin">Sign in</button>
<button type="submit" class="btn_style_1 btn" data-toggle="modal" data-target="#myModal">Join now</button>
</div>
</div>
</div>
</div>
When I run the application, the buttons are not working. Nothing happens when I click on the buttons. The cursor Is not transformed to a pointer when I hover the buttons.
However, when I remove centering col-lg-8 topSection, the Sign in button works, but not the other button.
Have anyone had the same problem?
EDIT:
I had this In my Layout.cshtml:
<div class="col-lg-12">
#RenderBody()
</div>
When I removed the div, It worked.
Remove the type="submit" or replace it with type="button". Your solution would be:
<button type="button" class="btn_style_1 btn" data-toggle="modal" data-target="#myModalLogin">Sign in</button>
<button type="button" class="btn_style_1 btn" data-toggle="modal" data-target="#myModal">Join now</button>
GOAL
Generate a drop-down list that contain a hyperlink in Laravel 4 using Blade
INFORMATION
I populated the list from my database data.
Everything work great, and it's display as a list of text.
Now, I want to turn those texts into hyperlink using the <a> tag.
I am not sure how to do that.
QUESTION
Am I close or at least on the right track ?
CODE
<?php $active = User::where('type','=','Distributor')->where('active','=', 1)->lists('username'); ?>
{{ Form::select('', $active,''array('href' => 'www.google.com' ) }}
Image
I'm not sure, how will you do that exactly, but I got some suggestion.
Rather than making a drop-down list,how about a button that will trigger a modal with a list of things that you want to list.
That the only way, that I think fit your case.
If you choose to do that, here is how to make that link
<a data-toggle="modal" data-target="#list" >Active</a>
According to your code, here is how I suggest for the Modal box, but of course, you can modify as you wish, this is just sample structure.
<div class="modal fade" id="list" >
<div class=" col-lg-4"> </div>
<div class=" col-lg-4">
<br><br><br><br><br>
<div class="modal-content">
<div class="modal-header" data-target="#modal-step-contents">
<button class="btn btn-danger btn-xs btn-white pull-right" data-dismiss="modal">
x
</button>
<h1 class="lighter">Active</h1>
</div>
<div class="modal-body step-content" id="modal-step-contents">
<td >
{{ $pending_distributor->company_name }}
</td>
</div>
<div class="modal-footer wizard-actions">
<button class="btn btn-danger btn-sm btn-next" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
I hope this help !