Twitter Bootstrap: using submit form as drop down menu items? - css

Instead of using anchors or buttons in a drop down menu, I want to have a form for each item. The form contains some hidden fields and a submit button. When I put the form in each <li> of my mark up, the UI was messed up. Does Bootstrap support this natively? If not, I'm going to re-code my application to work with links.
Update 1: screen shot
Update 2: mark up
<div class="btn-group open">
<button class="btn">Action</button>
<ul class="dropdown-menu">
<li>
<form action="#" method="post">
<fieldset>
<input type="submit" value="Favorite"/>
</fieldset>
</form>
</li>
<li>Message</li>
<li>
<form action="#" method="post">
<fieldset>
<input type="submit" value="Smile"/>
</fieldset>
</form>
</li>
<li>
<form action="#" method="post">
<fieldset>
<input type="submit" value="Block"/>
</fieldset>
</form>
</li>
<li>
<form action="#" method="post">
<fieldset>
<input type="submit" value="Friend"/>
</fieldset>
</form>
</li>
<li>
<form action="#" method="post">
<fieldset>
<input type="submit" value="Exclude From Future Search Results"/>
</fieldset>
</form>
</li>
</ul>
</div>
Update 3: icons
I want the submit buttons to have an icon. Not sure what's the best way to do that, but this is my solution:
<label for="foo">
<i class="icon-ok></i> Favorite
</label>
<input id="foo" style="display:none;" type="submit" value="Favorite"/>
The submit form is hidden, the label is shown with icon, and when user clicks on the label, it works. No JS required.

Not quite sure if I understand what you mean about the submit form being hidden but the label showing an icon however I was able to override the buttons with an image. Please see the attached jsBin. I did it by adding a class to the input's
http://jsbin.com/eboqij/1/edit
.button{
background-image:url('http://www.nyanicorn.com/res/img/icon_nyan.png');
background-repeat:no-repeat;
text-indent:-9999px;
width:40px!important;
}

Or just use Javascript to store the value in a hidden field and submit the form -- you're probably using JS anyways handle the open/close of the dropdown.
I had the exact same problem and I've created this new "submit" plug-in:
!function ($) {
"use strict"; // jshint ;_;
$(document).on('click.submit.data-api', '[data-submit]', function (e) {
e.preventDefault()
var form= $('#'+$(this).data('submit'))
form.find('input[name="'+$(this).data('name')+'"]').val($(this).data('value'))
form.submit()
})
}(window.jQuery);
Which I can use thus:
<form id="myform" ...>
<input type="hidden" name="myparam">
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Action
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a data-submit="myform" data-name="myfield" data-value="myvalue>
Click here
</a>
</li>
</ul>
</div>
</form>

Related

Make a bootstrap form, containing a button, appear inline next to another button

I want to move the "Delete page" button up next to the "View page" button. Is there an easy way to do this in bootstrap?
I don't want to wrap the h1 and "View page" button in the form, to preserve html readability.
<h1>
Edit page
<a target="_blank" class="btn btn-default" href="/view">View page</a>
<form role="form">
<input type="submit" name="commit" value="Delete page" class="btn btn-danger btn btn-primary" data-confirm="Are you sure?" />
</form>
</h1>
add display: inline to your form :
form{
display: inline;
}
https://jsfiddle.net/ypkLaexL/
An alternative solution would be to adjust your HTML. Adding a class of pull-right to the form will cause it to align to the right margin of your <h1> tag, and placing the hyperlink inside the <form> will cause the button to align as per your desired results.
Added bonus; you're not creating a class that overrides Bootstraps form framework.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<h1>
Edit page
<form role="form" class="pull-right">
<a target="_blank" class="btn btn-default" href="/view">View page</a>
<input type="submit" name="commit" value="Delete page" class="btn btn-danger btn btn-primary" data-confirm="Are you sure?" />
</form>
</h1>

Specific tab open on load

I'm using these tabs on a page to keep all the information needed on one page.
My question is, when I link from another page, would it be possible to open a specific tab on load? What should I look for? Hope You can help me out here.
Thank you.
<ul class="tabs">
<li>
<input type="radio" name="tabs" id="tab_how" checked />
<label for="tab_how">Something here</label>
<div id="tab-content" class="tab-content">
</div>
</li>
<li>
<input type="radio" name="tabs" id="tab_support" />
<label for="tab_support">Something else here</label>
<div id="tab-content" class="tab-content">
</div>
</li>
</ul>
Add a name or id to you ul as anchor:
<ul id="target_tab" class="tabs">
for the link:
Link
Hope this is what you are looking for.

How to automaticly place field next to each other user CSS bootstrap v3.2.0

I have create a future in my application that will allow me to create dynamic field on a page. What I need to do here is to display the those field the same way every time.
I want to be able to display up to 2 field next to each other "if any"
I have attached a screenshot on what I need the final display to look like
from the image below the field "No Longer an Employee" is a label and to the right of it there is a value in this case "NULL." And to the far right of it there is another field called "Outside Sales Primary Contact" with a value of "NULL."
So I want to display the field into 2 column if there is enough fields other wise put one on the left and nothing on the right.
not I don't need help with how to generate the field. I need help with CSS and bootstrap on how to display the column next to each other.
I may need some more details to clarify your question but I made you a demo codepen of what I think you're looking for.
DEMO - http://codepen.io/BooststrapBay/pen/DGzIu
<div class="container">
<div class="row">
<div class="col-md-6 example-form">
<ul>
<li>
<span>No longer an employee</span>
<input class="form-control" type="text">
</li>
<li>
<span>Support level</span>
<input class="form-control" type="text">
</li>
<li>
<span>Previous role</span>
<input class="form-control" type="text">
</li>
<li>
<span>Attitude</span>
<input class="form-control" type="text">
</li>
<li>
<span>Attitude detail</span>
<input class="form-control" type="text">
</li>
</ul>
</div>
<div class="col-md-6 example-form">
<ul>
<li>
<span>Outside sales primary contact</span>
<input class="form-control" type="text">
</li>
<li>
<span>Training primary contact</span>
<input class="form-control" type="text">
</li>
<li>
<span>Primary enrollment contact</span>
<input class="form-control" type="text">
</li>
<li>
<span>Birth month</span>
<input class="form-control" type="text">
</li>
<li>
<span>Birth day</span>
<input class="form-control" type="text">
</li>
</ul>
</div>
</div>
</div>

How can I align my search button to the right?

I'm not well versed in front end web design or CSS. Using a pre-made template from Foundation, however my code for a search button is not aligning like the example button.
Using this template: http://foundation.zurb.com/templates/workspace.html
Can someone tell me how I can move the search button to the right as in pic where the blue button is located?
This is what I am using now:
<input type="submit" value="Search" style="float: right;">
Fiddle: Search button code
<ul class="right">
<li class="search">
<li class="has-button">
/* Original template form */
{#<form>#}
{#<input type="search">#}
{#</form>#}
/* My form with code */
<form action="{{ path('sym_corp_search') }}" method="GET">
<label><input type="search" name="q" value={{ app.request.query.get('q') }}></label>
<input type="submit" value="Search" style="float: right;">
</form>
</li>
</li>
/* Original form button in blue */
<li class="has-button">
<a class="small button" href="#">Search</a>
</li>
Using the foundation classes, you can manage to perform this layout with your own inputs, your code will look like this:
<ul class="right">
<form action="{{ path('acme_demo_search') }}" method="GET">
<li class="search">
<label><input type="search" name="q" value="{{ app.request.query.get('q') }}" /></label>
</li>
<li class="has-button">
<input type="submit" value="Search" class="small button" />
</li>
</form>
</ul>
You have to use margin property like margin-left:50%; or more and you can also use ... tag but it will make button position to center. float:right is can be used in div, Not in button.
Move your button in a div :<div id="mybtn"><input type="submit" value="Search"></div> add CSS : #mybtn {float : right;display : inline-block;}

On onClick, click a DIV so it expands

I want that if you click on text the search button appears, I try to do that by using this code:
<a class="gn-icon gn-icon-search" style="width:200%;" onClick="CLICK ON THE BUTTON DIV">Search with style</a>
<ul id="sb-search" class="sb-search" style="margin-right:30px;">
<span class="sb-icon-search"></span>
<form>
<input class="sb-search-input" placeholder="Please enter search terms" type="text" value="" name="search" id="search">
<input class="sb-search-submit" type="submit" value="" id="search-submit">
</form>
</div>
Does someone knows how to fix this? Maybe with jQuery? Thank you very much!
Using JQuery you can show the button on link click.
The HTML:
<a class="gn-icon gn-icon-search" id="search-text" style="width:200%;">Search with style</a>
<ul id="sb-search" class="sb-search" style="margin-right:30px;">
<span class="sb-icon-search"></span>
<form id="search-form">
<input class="sb-search-input" placeholder="Please enter search terms" type="text" value="" name="search" id="search">
<input class="sb-search-submit" type="submit" value="" id="search-submit">
</form>
</ul>
The JQuery:
$(document).ready(function() {
$('#search-form').hide();
});
$('#search-text').click(function() {
$('#search-form').show();
});

Resources