Bootstrap multiple input form in a table - html

I want to create a table with several informational columns and one input.
I'm using bootstrap 3.0.
This is the example:
JsFiddle
The expected result is:
6 Columns:
1st and 2nd : would be string output.
3rd would be three inputs: Number, Letter, Letter
The rest are informational columns from three buttons: A, B, C.
The problem is that size of the third column is not matching the rest of the columns: 4, 5, 6.
Is it possible to achieve that only by changing the html?
The code:
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email number</label>
<input class="form-control" id="exampleInputEmail2" placeholder="Enter number" type="number">
</div>
Current wrong state with 3 rows of input:

Try using display:table-cell; for forms, and adjust width of inputs as you need, something like this:
.form-inline .form-control {
width: 50px;
display:table-cell;
}
.form-group{
display:table-cell;
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<table class="table table-striped table-advance table-hover">
<tbody>
<tr>
<td>John </td>
<td>Doe</td>
<td>
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email number</label>
<input class="form-control" id="exampleInputEmail2" placeholder="Enter number" type="number">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Enter Letter</label>
<input class="form-control" id="exampleInputEmail2" placeholder="Enter Letter" type="number">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputPassword2">Code Key</label>
<input class="form-control" id="exampleInputPassword2" placeholder="Key" type="text">
</div>
</form>
</td>
<td>
<div class="btn-row">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default active">
<input name="options" id="option1" type="radio"> A
</label>
<label class="btn btn-default">
<input name="options" id="option2" type="radio"> B
</label>
<label class="btn btn-default">
<input name="options" id="option3" type="radio"> C
</label>
</div>
</div>
</td>
<td>
<div class="btn-row">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default active">
<input name="options" id="option1" type="radio"> A
</label>
<label class="btn btn-default">
<input name="options" id="option2" type="radio"> B
</label>
<label class="btn btn-default">
<input name="options" id="option3" type="radio"> C
</label>
</div>
</div>
</td>
<td>
<div class="btn-row">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default active">
<input name="options" id="option1" type="radio"> A
</label>
<label class="btn btn-default">
<input name="options" id="option2" type="radio"> B
</label>
<label class="btn btn-default">
<input name="options" id="option3" type="radio"> C
</label>
</div>
</div>
</td>
</tr>
</tbody>
tbody>
</table>

Related

Resize text fields contained by Radio Button (form-check) div

I have a div which is "col-xs-8 col-xs-offset 2" that centers a form in the middle of the screen. Within this form I have two text areas and 4 radio buttons with corresponding text inputs for each. My problem is that while the text areas span the width of the container and resize appropriately when the window is resized, the inputs beside the radio button remain the same size until the browser is resized below their original length at which point they resize smaller. I would like these radio button text inputs to span in the same manner that the text areas do.
I hope this is clear enough.
<link rel="stylesheet" href="style.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<body class="container-fluid">
<div class="row">
<ol class="breadcrumb">
<li><span class="glyphicon glyphicon-home"</span></li>
<li>Create Quiz</li>
</ol>
<form method ="POST">
<div class="col-xs-8 col-xs-offset-2">
<fieldset class="form-group">
<legend class="text-center">
<label for="quiz_title" >Quiz Title:
</label>
</legend>
<div class="form-group">
<label for="question_text">Question</label>
<textarea class="form-control" id="explanation_text" rows="2"></textarea>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" name="answer" id="option1" value="radio_option1" required="required">
<label for="option1" class="form-check-label"> Answers: <a><span class="glyphicon glyphicon-pencil"></span></a>
<input class="form-control" type="text" id="option1" required="required">
</label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" name="answer" id="option2" value="radio_option2" >
<label for="option2" class="form-check-label">
<input class="form-control" type="text" id="option2" required="required">
</label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" name="answer" id="option3" value="radio_option3">
<label for="option3" class="form-check-label">
<input class="form-control" type="text" id="option3" required="required">
</label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" name="answer" id="option4" value="radio_option4">
<label for="option4" class="form-check-label">
<input class="form-control" type="text" maxlength="5" id="option4" required="required">
</label>
</div>
<div class="form-group">
<label for="explanation_text">Explanation</label>
<textarea class="form-control" id="explanation_text" rows="2" placeholder="Optional..."></textarea>
</div>
</fieldset>
</div>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-6">
<button type="submit" class="btn btn-primary center-block pull-right" name="question_submit"> Save Question </button>
</div>
<div class="col-xs-6">
<button type="submit" class="btn btn-primary center-block pull-left" name="quiz_submit"> Save Quiz </button>
</div>
</div>
</div>
</form>
</div>
</body>
Resizing Process:
Bootstrap has something called "Input Groups" that you might want to try. You can put the radio button next to a text input in an input group and the text input will fill up the remaining space. Look at some examples here: https://getbootstrap.com/components/#input-groups-checkboxes-radios
Here is something I put together using your code. Click on "Run code snippet" and then click "Full page" to see it in full page mode. Then you can resize the window to see how it will scale.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<ol class="breadcrumb">
<li><span class="glyphicon glyphicon-home"</span></li>
<li>Create Quiz</li>
</ol>
<form method ="POST">
<div class="col-xs-8 col-xs-offset-2">
<fieldset class="form-group">
<legend class="text-center">
<label for="quiz_title">Quiz Title:</label>
</legend>
<div class="form-group">
<label for="question_text">Question</label>
<textarea class="form-control" id="explanation_text" rows="2"></textarea>
</div>
<label for="option1">Answers: <a><span class="glyphicon glyphicon-pencil"></span></a></label>
<div class="input-group" style="margin-bottom:10px;">
<span class="input-group-addon">
<input type="radio" name="answer" id="option1" value="radio_option1" required="required">
</span>
<input type="text" class="form-control" id="option1" required="required">
</div>
<div class="input-group" style="margin-bottom:10px;">
<span class="input-group-addon">
<input type="radio" name="answer" id="option2" value="radio_option2" required="required">
</span>
<input type="text" class="form-control" id="option2" required="required">
</div>
<div class="input-group" style="margin-bottom:10px;">
<span class="input-group-addon">
<input type="radio" name="answer" id="option3" value="radio_option3" required="required">
</span>
<input type="text" class="form-control" id="option3" required="required">
</div>
<div class="input-group" style="margin-bottom:10px;">
<span class="input-group-addon">
<input type="radio" name="answer" id="option4" value="radio_option4" required="required">
</span>
<input type="text" class="form-control" id="option4" required="required">
</div>
<div class="form-group">
<label for="explanation_text">Explanation</label>
<textarea class="form-control" id="explanation_text" rows="2" placeholder="Optional..."></textarea>
</div>
</fieldset>
</div>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-6">
<button type="submit" class="btn btn-primary center-block pull-right" name="question_submit"> Save Question </button>
</div>
<div class="col-xs-6">
<button type="submit" class="btn btn-primary center-block pull-left" name="quiz_submit"> Save Quiz </button>
</div>
</div>
</div>
</form>
</div>
</div>

Twitter bootstrap btn-group doesn't allow inline text on your right?

I am trying to display 3 divs (a radio button, a button group and a select) inside a form on the same line and in that order, but I still keep failing.
I have tried this solution but didn't helped me. I really don't know if this is a common problem or I am missing something.
PICTURE
HTML
<form>
<div class="form-group row">
<div class="col-sm-2">
<label for="f-option1">
<input onClick="doSomething()" type="radio" id="f-option1" name="selector" checked>
My radio button</label>
</div>
<div class="btn-toolbar">
<label for="inputEmail3" class="col-sm-1 control-label">My group button:</label>
<div class="col-sm-2 btn-group" data-toggle="buttons">
<label class="btn btn-default"><input type="radio" name="options" id="option5">10</label>
<label class="btn btn-default"><input type="radio" name="options" id="option6">30</label>
<label class="btn btn-default"><input type="radio" name="options" id="option7">60</label>
<label class="btn btn-default"><input type="radio" name="options" id="option8">90</label>
</div>
</div>
<label for="inputEmail2" class="col-sm-1 col-form-label">My select:</label>
<div class="col-sm-2">
<select class="form-control" id="sel1">
<option>1</option>
<option>2</option>
</select>
</div>
</div>
</form>
Try This.
<div class="form-group row">
<div class="col-sm-2">
<label for="f-option1">
<input onclick="doSomething()" type="radio" id="f-option1" name="selector" checked="">
My radio button</label>
</div>
<div class="btn-toolbar" "="">
<label for="inputEmail3" class="col-sm-1 control-label">My group button:</label>
<div class="col-sm-2 btn-group" data-toggle="buttons">
<label class="btn btn-default"><input type="radio" name="options" id="option5">10</label>
<label class="btn btn-default"><input type="radio" name="options" id="option6">30</label>
<label class="btn btn-default"><input type="radio" name="options" id="option7">60</label>
<label class="btn btn-default"><input type="radio" name="options" id="option8">90</label>
</div>
<label for="inputEmail2" class="col-sm-1 col-form-label">My select:</label>
<div class="col-sm-2">
<select class="form-control" id="sel1">
<option>1</option>
<option>2</option>
</select>
</div>
</div>
</div>
Here is one variant of solution. You need just do inline label and dropdown list. Open full page to see result.
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<form>
<div class="col-lg-4">
<label for="f-option1">
<input onClick="doSomething()" type="radio" id="f-option1" name="selector" checked>My radio button
</label>
</div>
<div class="col-lg-4">
<div class="input-group">
<label for="inputEmail3" class="control-label">My group button:</label>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" name="options" id="option5">10</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option6">30</label>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="input-group">
<label for="inputEmail2" class="control-label">My select:</label>
<select class="form-control" id="inputEmail2">
<option>1</option>
<option>2</option>
</select>
</div>
</div>
</form>
</div>
</div>

Separate button group

How do I separate two radio button groups ? Each line have to be checked separately, see in the example below :
<div id="group1" class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input id="emViewMacsButton" name="options" type="radio">MAC
</label>
<label class="btn btn-primary">
<input id="emViewTagsButton" name="options" type="radio">Tags
</label>
<label class="btn btn-primary">
<input id="emViewSettingsButton" name="options" type="radio">Settings
</label>
</div>
<div id="group2" class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input id="emViewMacsButton2" name="options" type="radio">MAC
</label>
<label class="btn btn-primary">
<input id="emViewTagsButton2" name="options" type="radio">Tags
</label>
<label class="btn btn-primary">
<input id="emViewSettingsButton2" name="options" type="radio">Settings
</label>
</div>
https://jsfiddle.net/vzn6x7z6/
Thanks
You need to separate your groups with <fieldset> , and also you need to wrap it in <form>, and finally to work as you want you need to change name for second group from name="option" to name="optionOne" or something.
updated jsFiddle
<form>
<fieldset>
<div id="group1" class="btn-group" data-toggle="buttons">
<input id="emViewMacsButton" name="options" type="radio">
<label class="btn btn-primary">MAC</label>
<input id="emViewTagsButton" name="options" type="radio">
<label class="btn btn-primary">Tags</label>
<input id="emViewSettingsButton" name="options" type="radio">
<label class="btn btn-primary">Settings</label>
</div>
</fieldset>
<fieldset>
<div id="group2" class="btn-group" data-toggle="buttons">
<input id="emViewMacsButton2" name="options1" type="radio">
<label class="btn btn-primary">MAC</label>
<input id="emViewTagsButton2" name="options1" type="radio">
<label class="btn btn-primary">Tags</label>
<input id="emViewSettingsButton2" name="options1" type="radio">
<label class="btn btn-primary">Settings</label>
</div>
</fieldset>
</form>
Also match for attribute of label with input ID, and move input outside of label. Everything is updated in code above except for attributes.
Put them in 2 separate fieldsets instead of a div and it should work:
<fieldset>
<label class="btn btn-primary">
<input id="emViewMacsButton" name="options" type="radio">MAC
</label>
<label class="btn btn-primary">
<input id="emViewTagsButton" name="options" type="radio">Tags
</label>
<label class="btn btn-primary">
<input id="emViewSettingsButton" name="options" type="radio">Settings
</label>
</fieldset>
<fieldset>
<label class="btn btn-primary">
<input id="emViewMacsButton2" name="options" type="radio">MAC
</label>
<label class="btn btn-primary">
<input id="emViewTagsButton2" name="options" type="radio">Tags
</label>
<label class="btn btn-primary">
<input id="emViewSettingsButton2" name="options" type="radio">Settings
</label>
</fieldset>

I want to enable and disable radio button group using a check box

html code where button groups are declared
<tr>
<div class="checkbox">
<td class="fc">INACTIVE <label> <input type="checkbox" data-toggle="toggle-checkbox" ng-change="isCheckboxChecked()" > </label></td>
<td style="visibility:$scope.isCheckboxChecked()=="true"">
<div class="btn-group">
<label class="btn-primary btn ">
<input type="radio" name="options4" ng-model=" option4" value="rewards" ng-required="!option4" > Rewards
</label>
<label class="btn-primary btn ">
<input type="radio" name="options4" ng-model=" option4" value="awards" ng-required="!option4"> Awards
</label>
<label class="btn-primary btn">
<input type="radio" name="options4" ng-model=" option4" value="offers" ng-required="!option4"> Offers
</label>
</div>
</td>
</tr>
angular script for that checkbox.
validationApp.controller('mainController', function($scope) {
$scope.isCheckboxChecked = function() {
return ($scope.isCheckboxChecked(true)
);
}
}
try this
HTML
<tr>
<div class="checkbox"><td class="fc">INACTIVE <label> <input type="checkbox" ng-model="isChecked" > </label></td>
<td ng-if="isChecked==true"><div class="btn-group">
<label class="btn-primary btn ">
<input type="radio" name="options4" ng-model=" option4" value="rewards" ng-required="!option4" > Rewards
</label>
<label class="btn-primary btn ">
<input type="radio" name="options4" ng-model=" option4" value="awards" ng-required="!option4"> Awards
</label>
<label class="btn-primary btn">
<input type="radio" name="options4" ng-model=" option4" value="offers" ng-required="!option4"> Offers
</label>
</div></td>
</tr>
JS
No need of any JS. ;)
Ng-disabled on fieldset is that what you need.
<tr>
<div class="checkbox">
<td class="fc">INACTIVE <label><input type="checkbox" data-toggle="toggle-checkbox" ng-model="checked" ></label></td>
<td>
<fieldset class="btn-group" ng-disabled="checked">
<label class="btn-primary btn ">
<input type="radio" name="options4" ng-model=" option4" value="rewards" ng-required="!option4" > Rewards
</label>
<label class="btn-primary btn ">
<input type="radio" name="options4" ng-model=" option4" value="awards" ng-required="!option4"> Awards
</label>
<label class="btn-primary btn">
<input type="radio" name="options4" ng-model=" option4" value="offers" ng-required="!option4"> Offers
</label>
</fieldset>
</td>
</div>
</tr>

Bootstrap radio button "checked" flag

In case #1 works, in case #2 it do not works. Check the code bellow:
<div class="container">
<div class="row">
<h1>Radio Group #1</h1>
<label class="radio-inline">
<input name="radioGroup" id="radio1" value="option1" type="radio"> 1
</label>
<label class="radio-inline">
<input name="radioGroup" id="radio2" value="option2" checked="checked" type="radio"> 2
</label>
<label class="radio-inline">
<input name="radioGroup" id="radio3" value="option3" type="radio"> 3
</label>
</div>
<div class="row">
<h1>Radio Group #2</h1>
<label for="year" class="control-label input-group">Year</label>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input name="year" value="2011" type="radio">2011
</label>
<label class="btn btn-default">
<input name="year" value="2012" type="radio">2012
</label>
<label class="btn btn-default">
<input name="year" value="2013" checked="checked" type="radio">2013
</label>
</div>
</div>
</div>
You can see it in action here: http://bootply.com/84165
Assuming you want a default button checked.
<div class="row">
<h1>Radio Group #2</h1>
<label for="year" class="control-label input-group">Year</label>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" name="year" value="2011">2011
</label>
<label class="btn btn-default">
<input type="radio" name="year" value="2012">2012
</label>
<label class="btn btn-default active">
<input type="radio" name="year" value="2013" checked="">2013
</label>
</div>
</div>
Add the active class to the button (label tag) you want defaulted and checked="" to its input tag so it gets submitted in the form by default.
A javascript fix to apply the 'active' class to all labels that are parents of checked inputs:
$(':input:checked').parent('.btn').addClass('active');
insert right after
$('.btn').button();
You have to use active in the label to make it work as mentioned above. But you can use checked="checked" and it will work too. It's not necessary but it's more legible and makes more sense as it is more html format compliance.
Use active class with label to make it auto select and use checked="" .
<label class="btn btn-primary active" value="regular" style="width:47%">
<input type="radio" name="service" checked="" > Regular </label>
<label class="btn btn-primary " value="express" style="width:46%">
<input type="radio" name="service"> Express </label>
In case you want to use bootstrap radio to check one of them depends on the result of your checked var in the .ts file.
component.html
<h1>Radio Group #1</h1>
<div class="btn-group btn-group-toggle" data-toggle="buttons" >
<label [ngClass]="checked ? 'active' : ''" class="btn btn-outline-secondary">
<input name="radio" id="radio1" value="option1" type="radio"> TRUE
</label>
<label [ngClass]="!checked ? 'active' : ''" class="btn btn-outline-secondary">
<input name="radio" id="radio2" value="option2" type="radio"> FALSE
</label>
</div>
component.ts file
#Component({
selector: '',
templateUrl: './.component.html',
styleUrls: ['./.component.css']
})
export class radioComponent implements OnInit {
checked = true;
}