how to add glyphicon to bootstrap dropdown menu - css

Im trying to add a glyphicon to the left of a link in a dropdown menu, but cant seem to figure it out. This is what my code looks like:
<div class="col-md-4">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">options
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><i class="glyphicon glyphicon-flag"></i><%=link_to "report link", report_path(report: {reportable_id: post.id, reportable_type: "Post"}), id: "report_#{post.class}_#{post.id}", class: "report_link", remote: true, method: :post %></li>
Can someone please explain to me how to do this?
Thanks!

Simply put the icon inside the link - there's no visual downside to doing so, and even potentially improves UX (you can click on the icon too).
<li><i class="glyphicon glyphicon-flag"></i> link</li>
See this bootply
So your new ruby link would look like
<%=link_to "<i class='glyphicon glyphicon-flag'></i> report link".html_safe, report_path(report: {reportable_id: post.id, reportable_type: "Post"}), id: "report_#{post.class}_#{post.id}", class: "report_link", remote: true, method: :post %>
(Apologies if this is wrong, I don't actually know Ruby. I assume this was a css positioning error, but if the Ruby is wrong too let me know and I shall delete this answer)

Try using a span outside of your link_to. You would remove the display text ("report link") after the link_to and add it back after the Glyphicon span class ends.
<li>
<%=link_to report_path(report: {reportable_id: post.id, reportable_type: "Post"}), id: "report_#{post.class}_#{post.id}", class: "report_link", remote: true, method: :post do %>
<span class="glyphicon glyphicon-flag"></span> Report Link
<% end %>
</li>

Related

GTM: Cannot track click on menu elements

I want to capture all click events on the menu of my page.
I've setup a tag that will capture all click events on my page. It works with the trigger setup to "Click - All elements".
When I set up the trigger to specifically register only the clicks on elements of the menu var, nothing is detected. So, definetly, I'm doing somenthing wrong within the trigger.
EDIT 1:
this is the web page: www.chazki.com
Menu code:
<div class="collapse navbar-collapse" id="navbar-ex-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">
<a class="new_service">Solicita un Chazki</a>
</li>
<li>
Faq
</li>
<li>
<p class="new_service new-service" style=" padding: 6px;"><a>Login</a></p>
</li>
<li>
<a class="btn btn-default btn-lg location_ac"><i class="fa fa-fw fa-spin fa-star"></i>Lima</a>
</li>
</ul>
<form>
<fieldset class="navbar-form navbar-left">
<input type="text" name="track-code" id="track-code" class="form-control" placeholder="Código de tracking?">
<button id="track-find-button" class="btn btn-default" type="button">Buscar</button>
</fieldset>
</form>
</div>
Try 1 on trigger:
Element ID: It's supposed to limit the clicks registered for only the div containing the menu.
I get this error in debugging mode:
Try 2 on trigger:
on Click ID.
Click ID error:
#
I could also use the ul tag for the trigger, as it is the only unordered list on the page.
Any hint is welcome. Thanks!
Basically I needed to understand the different variables in GTM. I've found Simo Ahava web very helpful in this regard.
https://www.simoahava.com/analytics/variable-guide-google-tag-manager/
Thanks to Simo, I also understood the benefits of usen "Match CSS Selector" option.
So my configuration ended like this:
Using:
Click All Elements.
This trigger fires on "Some Clicks".
"Click Element" -> "Matches CSS Selector" -> "#navbar-ex-collapse ul li a, #navbar-ex-collapse ul li p"
As I have li and a html elements, I needed to use 2 CSS selectors, separated by a comma.

How can I use Glyphicons with JSF?

How can i use glyphicons with JSF(Netbeans: Maven/web application+JSF Framework)? I want to use a glyphicon with a <h:link>.
Here is how I did it in regular HTML:
<li><span class="glyphicon glyphicon-home"></span> Home</li>
Here is how that looked like:
Here is how I tried to do it in JSF:
<li><h:link id="bone" value="Home" outcome="book" /><span class="glyphicon glyphicon-plane"></span></li>
Here is how it looked like:
As you can see, the glyphicon which is black and a little hard to see in that darkblue background color, is located down there. How do I make it to look like the HTML version but in JSF?
Ps, the "home button" is part of a navigation bar.
Thanks.
When you use this code:
<h:link id="bone" value="Home" outcome="book" />
<span class="glyphicon glyphicon-plane"></span>
Your generated HTML code will be:
<span class="glyphicon glyphicon-home"></span> Home
Try like this:
<li>
<h:link id="bone" outcome="book">
<span class="glyphicon glyphicon-plane"></span>Home
</h:link>
</li>
In short: the order you place the JSF code matters.

Bootstrap dropdown: change dropdown icon when it's active?

I have the following setup:
<div data-ng-repeat="item in navigationBar.navObject.items" class="btn-group">
<button data-ng-class="{current: $last}" class="btn btn-default btn-xs" type="button" data-ng-click="navigationBar.goToState(item)"> {{item.name}}</button>
<button data-ng-hide="item.isTerminal" data-toggle="dropdown" class="btn btn-default btn-xs dropdown-toggle" type="button">
<span class="fa fa-fw fa-caret-right"></span>
</button>
<ul class="dropdown-menu">
<li data-ng-repeat="subItem in item.subItems"><a data-ng-click="subItem.item.goToState()">{{subItem.name}}</a></li>
</ul>
</div>
And I would like the icon in the dropdown to change from fa-caret-right to fa-caret-down when the dropdown list is visible. Is there any way to do this strictly with CSS?
You won't be able to change the attributes of HTML elements using CSS, you'll probably want to use jQuery instead.
Bootstrap has some nifty JavaScript going on, where you can execute your own scripts when boostrap elements inside your website is used.
Initialize dropdown using this inside jQuery.
$('.dropdown-toggle').dropdown();
When it's called you can hook different actions to it using the handles specified on the bootstrap docs.
on('show.bs.dropdown', function(){}); is just a fancy word for saying "on dropdown"
$('.dropdown-toggle').on('show.bs.dropdown', function () {
// All actions to fire after the dropdown is shown go here.
$('.fa .fa-fw').addClass('fa-caret-right');
$('.fa .fa-fw').removeClass('fa-caret-down');
})
I know this is an old post, but I was looking for this solution and have one that works for me. You can target and change the pseudo element inside that span. When you click the button, doesn't the button add an open class? So, then the css would look like:
btn.open .fa-caret-right:before { content: "\e114"; }
Use the .open added to the button class.
The \e114 being the character of the down arrow.

CSS Find not working with Poltergeist

The following is my html source:
<div id="users_filter" class="btn-group no-margin pull-right nested-pull-right open">
<a class="btn dropdown-toggle attach-left btn-small btn-primary" data-toggle="click-dropdown" href="#"></a>
<ul class="dropdown-menu dropdown-filter"></ul>
</div>
I have the following step definition:
When /I click "([^\"]*)"/ do |arg1|
find(:css, arg1).trigger('click');
end
And now In my feature file i do:
Then I click "#users_filter .dropdown-toggle"
But the click event does not get triggered.
I use Capybara & Poltergeist driver.
Can someone please help me understand where I'm going wrong?
Thanks
Ramya

Creating a split-button-dropdown in asp.net MVC with Twitter Bootstrap

I am trying to create a split button dropdown using Bootstrap and ASP.NET MVC 5, but I cannot seem to render the correct markup. This is what I have so far...
<div class="btn-group">
#Html.ActionLink("Details", "Details", new { id = item.ClientTypeID }, new { #class = "btn btn-sm btn-primary" })
<a class="btn btn-sm dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>#Html.ActionLink("Edit", "Edit", new { id = item.ClientTypeID })</li>
<li>#Html.ActionLink("Delete", "Delete", new { id = item.ClientTypeID })</li>
</ul>
</div>
I have no doubt that this is my own fault, but can anybody please point out what I should actually have in my template. Instead of the required drop down, I am seeing the initial "Details" button, and I am seeing the drop down caret, but clicking on the caret does not show the additional items.
In case it makes a difference, I am using the default templates from VS2013 along with the Cosmo theme from Bootswatch. This is also being rendered in a table cell.
Thanks.
Make sure you have registered jQuery before bootstrap.min.js.
Debug the error using Developer Tools available in all modern browsers.
Chrome use Ctrl+J, IE use F12, FireFox use Shift+F2
Happy Coding..

Resources