I have what I think is a very basic problem but to which I cannot find the solution. So I have a form in my rails project. I want to create an input field, and two buttons associated with that field so I can add another type of input field.
If I click on the green button, I append another set of the same 3 fields.
<div class="col-md-2">
<%= f.input :select1, collection: #traffic_vault.sort + [["------ Aggregations ------ ", ""]] + #traffic_vault_aggregations.sort, include_blank: false, label: "Select Dimensions (*)", input_html: {class: "remember_timestamp", type: "text" } %>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-success" onclick="apply_function(0)">Apply Function</button>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-success" onclick="rename(0)">Rename It</button>
</div>
My problem is that the input field is working fine by taking exactly the col-md that I put there, but the buttons are not, they are taking slightly less space, not exactly col-md-2. So, when adding more fields to the first image, since the buttons are not exactly col-md-2, I get this:
I found out the problem is with the buttons because if I change it to inputs, it is working perfectly.
As we can see, they all have the same space between them, and each of them is col-md-2, so when adding 6 of these fields, you have col-md-12, so anymore fields added will be placed below and so on, but not with the buttons.
What is the problem?
solution: thanks to Siim for the answer. By placing style="width:100%;" button will take all available width. But still, i have a problem where, even if the buttons are col-md-2, like the inputs from before, if i add a 3rd set of fields, its not being placed correctly like in the 3rd image with the inputs, where the new set is placed at the beginning of another row.
Add w-100 class to the button. This tells the button to take up 100% of the available space.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-4">
<label>
<input class="form-control">
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-success">
btn
</button>
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-success w-100">
btn
</button>
</div>
</div>
</div>
Related
I am working on a web app that is to store sport cards, and we already have a functioning search bar. In order to make things easier on the user, we want to add buttons beneath the search bar that would filter the sport cards by their sport. While you could just search for "baseball" and it would accomplish the same thing... the client wants a specific look.
Here is our search bar:
<div class="col-md-12">
<div class="input-group" id="searchBar">
<span class="input-group-addon" id="sizing-addon1"><span class="glyphicon glyphicon-search"></span></span>
<input type="text" class="form-control" placeholder="Search" ng-model="query"/>
</div>
</div>
And our table:
<div class="grid-container">
<div class="grid-item" ng-repeat="listing in listings | filter:query" >{{listing.playerName}}, {{listing.playerTeam}}
<br>
<br>
<button ng-click="deleteListing(listing._id)">Remove</button>
<button ng-click="addToCart(listing._id)">Add to cart</button>
<button ng-click="showDetails(listing._id)" data-toggle="modal" data-target="#exampleModal2">Details</button>
</div>
</div>
I am just having troubles figuring out what the button should do exactly. Is there a way to simply hard-code an input when the button is clicked? Will I need to write a new function to filter elements by sport type?
I have a basic Bootstrap input group with an input and button. Everything looks fine when the browser is a "normal" width. However when I extend it to a 2nd monitor there is a space that appears between the input control and the button. Looked around, but I have been unable to find a solution that will keep these together in a way similar to how the btn-group works.
Here's my code:
<div class="row">
<div class="col-md-2 col-md-offset-1">
<div class="input-group">
<input id="SearchText" class="form-control" type="text">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</div>
Thanks in advance!
Update:
After messing with this a little more, it appears it has something to do with the column attributes. If I make the outer div col-md-1 instead, it won't create the space. However this makes the input too small for what I need it for. Also, I'm guessing that if I extended the browser far enough the space would reappear.
Found a solution that appears to work so I thought I'd share it in case others have a similar issue.
After looking at this more, I discovered that the separation of the input from the button was happening whenever the input control reached its maximum width. In order to maintain the desired proportion dictated by the column attribute tags it created a space between the input and the button (why it doesn't just add blank space after the button, I don't know). There are two ways I found to accomplish what I was wanting:
The first is to directly adjust the maximum width of the input control. This allows the input control to expand and fill the extra space. This can be done in a number of places (css stylesheet, jquery/javascript, or in the tag itself in the html). I went ahead and included it in the stylesheet.
The second way is to include a col-lg-* attribute that is smaller than the col-md-* attribute. This reduces the proportion of the size of the input control in relation to the screen and reduces the likelihood it will reach it's maximum width (it also keeps your input control from expanding nearly as much). (Note: if you use this method I would suggest adjusting the minimum width of your input controls to keep a more consistent size).
In the end I ended up using both methods to keep my input controls about the same size and ensure that someone would have to use a ridiculously large monitor to separate the input and button.
CSS:
input.form-control {
max-width: 400px;
min-width: 200px;
}
HTML:
<div class="row">
<div class="col-md-2 col-md-offset-1 col-lg-1">
<div class="input-group">
<input id="SearchText" class="form-control" type="text">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</div>
Hope this helps someone
I am trying to make a button show and hide a div. I think I almost have it done, but I am missing this very last part.
Here is what I would like to happen: when you click on the red "change template" button, the text changes to "back to page 1". Now click on the red button again. The one that says "back to page 1" - I need that to actually change the div below to the yellow box. Right now it does nothing when you click on the red button the second time.
I would also need the text to change back to "change template". I am thinking what I need is a toggle button.
I have tried to implement multiple toggle buttons I found on stackoverflow already, but it seems my other code might be getting in the way. I made a plunker so its easy to see the problem.
http://plnkr.co/edit/RpqoXXHGBeYaBzIlD8Qb?p=preview
<div class="btn top-menu-button finchbutton red" ng-click="finchange='show';finpage1='';finpage2='';finpage3='';hellotext='hide';goodbyetext='show'">
<span class="btntext" ng-class="hellotext">Change Template</span><span class="btntext" ng-class="goodbyetext">Back To Template</span></div>
<div class="btn top-menu-button finbutton1 orange" ng-click="finpage1='show';finpage2='';finpage3='';finchange='';hellotext='show';goodbyetext='hide'">Page 1</div>
<div class="btn top-menu-button finbutton2 blue" ng-click="finpage2='show';finpage1='';finpage3='';finchange='';hellotext='show';goodbyetext='hide'">Page 2</div>
<div class="btn top-menu-button finbutton3 pink" ng-click="finpage3='show';finpage1='';finpage2='';finchange='';hellotext='show';goodbyetext='hide'">Page 3</div>
As per your code, whenever you click on the button it will always hide "hellotext" and show "goodbyetext"
What you need to do is add is a function which checks for the value of hellotext and/or goodbyetext and toggle it based on values
Hope it helps!!
If I get you right you need a toggle button behavior. This case it will be more naturally to use ng-show/ng-hide
<div ng-app="ngAnimate" ng-init="firstOn=true;">
<div class="btn top-menu-button finchbutton red" ng-click="firstOn = !firstOn;">
<span class="btntext" ng-show="firstOn">Change Template</span><span ng-hide="firstOn" class="btntext">Back To Page 1</span></div>
<div class="btn top-menu-button finbutton1 orange" ng-click="">Page 1</div>
<div class="btn top-menu-button finbutton2 blue" ng-click="">Page 2</div>
<div class="btn top-menu-button finbutton3 pink" ng-click="">Page 3</div>
<br>
<span class="template-panel red" ng-show="!firstOn">Red</span>
<span class="template-panel orange" ng-show="firstOn">Orange</span>
<span class="template-panel blue hide">Blue</span>
<span class="template-panel pink hide">Pink</span>
</div>
You can see the example (I simplified yours a little to have the idea clear) at http://plnkr.co/edit/es5pgmrgsXbm6bP8CSrr
I'm trying to create an input-group of 3 controls. The following :
1. Filter dropdown of sort (Currently using <select>
2. The input text box
3. The Search button
I've managed to get the latter 2 working as expected, they both join up and appear as expected however when I try to add a select control although in-line it doesn't seem to have the same height as the other 2 controls. I've tried all sorts of combinations and have ran out of ideas to try.
On the bootstrap documentation they have not shown how to do this with a but with a dropdown control however when I tried to do that with I could not get it to work as the control does.
Could someone suggest how I could add the filter control? Here is an example of the data in my angular controller $scope.filterOptions = ["test", "test2", "test3"].
What I essentially what to achieve is something similar to that of the bootstrap documentation example :
Here's the non-working html I have at the moment.
<div class="panel-heading clearfix">
<form class="input-group col-md-4">
<div class="input-group-btn">
<select class="btn btn-default" ng-model="filterOption">
<span class="caret"></span>
<option ng-repeat="option in filterOptions" value="{{option}}">{{option}}</option>
</select>
</div>
<input type="text" ng-model="query" class="form-control" placeholder="Enter ID / Name">
<div class="input-group-btn">
<button ng-click="search()" type="submit" class="btn"><i class="glyphicon glyphicon-search"></i></button>
</div>
</form>
</div>
Here's a plunkr I made which shows the same problem : http://plnkr.co/edit/uDFmFZSbIMBP4DqalhQC?p=preview
Height of the select compared to the button in the bootstrap example is less so giving a height to the select will make it same as other controls.
By default
CSS
select {height: 34px;}
Demo here
I've been getting this weird bug with Bootstrap Modals for a few days now, and can't seem to find any sort of answer online. I'd be grateful for any sort of help on this.
My site uses AngularJS + Bootstrap. The specific part I'm working on right now has two buttons that bring up a modal, and a grid below them that shows the user a bunch of info. The weird part is, the button that allows users to create an entry on the grid will bring up a form, but not allow them to edit the first two fields. The second button, which lets users edit an entry on the grid, is pretty much formatted the same as the create button, yet that works fine. This also only occurs on page refresh only, and is resolved after the user clicks the edit button to bring up that modal, then closes that. Afterward, the create modal will work fine. Here is the code for these parts of the site:
Modal Buttons:
<div class="row-fluid" ng-init="getAllSources()">
<!-- Create Source Modal Button -->
<button class="btn btn-success" data-toggle="modal" data-target="#createSource" ng-click="initCreateSource()">+ Create Source</button>
<!-- Edit Source Modal Button -->
<button class="btn btn-primary pull-right" data-toggle="modal" data-target="#editSource">Edit Source</button>
<!-- Sources Grid -->
<div ng-show="visible.grid == true" class="edus-admin-manage-grid" style="margin-left:0;" ng-grid="sourceGridOptions"></div>
</div>
Modals:
<div class="modal fade" id="createSource" tabindex="-1" role="dialog" aria-labelledby="createSourceLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="createSourceModal">Create Source</h4>
</div>
<div class="modal-body" ng-include="'source-create.html'"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="getAllSources()" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" ng-click="getAllSources()" data-dismiss="modal">Save</button>
</div>
</div>
</div>
</div>
(The Edit Sources Modal looks the exact same as the Create Sources Modal, with the exception of a different link in the ng-include, and some labels here and there)
Here is the part of the code that doesn't 'work' on page refresh:
<form name="form" novalidate>
<div class="row-fluid">
<label for="inputID">* Source Id</label>
<label for="inputName">* Source Name</label>
</div>
<div class="row-fluid">
<input type="text" class="span4" id="inputId" placeholder="Title" ng-model="createSource.createId" required>
<input type="text" class="span8" id="inputName" placeholder="Source Name" ng-model="createSource.createName" required>
</div>
<div class="edus-admin-manage-label-rows row-fluid ">
<label class="edus-admin-manage-label span4" for="inputId">* Activity Name</label>
<label class="edus-admin-manage-label span4" for="inputName">* Activity Label</label>
</div>
<div class="row-fluid form-inline">
<select class="span4" ng-model="activityType.activity" ng-options="value.name for value in multipleActivityTypes" data-style="btn" bs-select></select>
<select class="span4" ng-model="activityType.label" ng-options="value for value in activityLabels" data-style = "btn" bs-select></select>
<input class="btn btn-default span4" type="submit" ng-click="activityTypeSubmit()" value="Add Activity" data-style="btn"/>
</div>
...
</form>
Everything else after the '...' in the third snippet of the code works - I just can't select any options from the pull down menu, or input anything for the Source Id/Name fields. I figured the ngClick I had in the Create Source button that brought up the modal could've been the problem, so I removed that to see if the form was editable - no luck there. Any help is greatly appreciated!
Update:
Originally, I had my HTML organized as so:
<div>
<!-- Modal Buttons -->
</div>
<!-- Modals -->
When I moved my modals back into the divs that contained the buttons, like so:
<div>
<!-- Modal Buttons -->
<!-- Modals -->
</div>
everything worked as intended. This seems like some sort of scoping issue, which I didn't think would cause a problem in HTML - can anyone shed some light on this type of problem?
It's very hard to determine issue when you paste it here wildly. Please use plunker for such issues. And look at this demo in Plnkr
Consider your data structure is like
$scope.activityType = {
'activityType.activity': {}
};
$scope.multipleActivityTypes = [
{
'name': 'asd',
'val': 123
},
{
'name': 'qwe',
'val': 234
}
];
p.s. i should comment this, but not enought pts. so sorry for that