toggle radio button in html bootstrap 3.4 - html

here i am trying to toogle radio button
here it is i want answer like this
i tried for this like
<label class=" btn-lg btn-primary btn-block">
<input type="radio" :id="choice.id" >Answer {{choiceKey+1}} {{ choice.choice }}
</label>
but it get all color like this

You don't necessarily need JS for this, you can do it CSS-only with the adjacent sibling selector (+). Rough example below:
input[type=radio] {
display: none;
}
input[type=radio]:not(:checked) + label {
background-color: gray;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<input type="radio" name="something" id="radio_1">
<label for="radio_1" class="btn-lg btn-primary btn-block">Answer 1</label>
<input type="radio" name="something" id="radio_2" checked>
<label for="radio_2" class="btn-lg btn-primary btn-block">Answer 2</label>
<input type="radio" name="something" id="radio_3">
<label for="radio_3" class="btn-lg btn-primary btn-block">Answer 3</label>
<input type="radio" name="something" id="radio_4">
<label for="radio_4" class="btn-lg btn-primary btn-block">Answer 4</label>

Edited. I think it's more what you're looking for.
Starting point, in the Bootstrap docs, see here. For this approach you will need jQuery.
Also note that each radio button needs the same name attribute so they all work together; when you click one, the others turn off.
$("input[type=radio]").change(function() {
// remove the background color from all labels.
$("label").removeClass("btn-primary");
// add the background only to the parent-label of the clicked button.
$(this).parent().addClass("btn-primary");
});
label {
border: 1px solid #204d74 !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary btn-block active">
<input type="radio" name="options" id="option1" checked> Radio 1 (preselected)
</label>
<label class="btn btn-block">
<input type="radio" name="options" id="option2"> Radio 2
</label>
<label class="btn btn-block">
<input type="radio" name="options" id="option3"> Radio 3
</label>
</div>

Related

Radio buttons all active at once when I load the page in Bootstrap 4.5

<div class="form-row">
<div class="column">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-primary active" for="visualContagi">
<input type="radio" name="options" id="visualContagi" checked> Contagi
</label>
<label class="btn btn-primary" for="visualGuariti">
<input type="radio" name="options" id="visualGuariti" checked> Guariti
</label>
<label class="btn btn-primary" for="visualDecessi">
<input type="radio" name="options" id="visualDecessi" checked> Decessi
</label>
<label class="btn btn-primary" for="visualRicoveri">
<input type="radio" name="options" id="visualRicoveri" checked> Ricoveri
</label>
<label class="btn btn-primary" for="visualTotPos">
<input type="radio" name="options" id="visualTotPos" checked> Totale Positivi
</label>
</div>
</div>
</div>
Hi, I have this radio button group as part of a form. The problem is that the buttons all get the "active" class applied to them when I load the webpage. I haven't written any javascript, it's just bootstrap, and this CSS applied to remove the outline when I click on the buttons:
.btn-primary.focus, .btn-primary:focus {
box-shadow: none;
}
I'm using the latest version of Firefox on macOS.
What I am noticing is that each of your <input type="radio" elements have the checked attribute attatched to them. If you remove that, then it should be fixed. I hope this helps!

Bootstrap disabling radio btn-group with data-toggle=buttons

I am using bootstrap 3.3.6 and I am trying to disable this type of radio btn-group. I've tried placing the disabled on both the label and input, but it doesn't seem to work. The buttons would appear as disabled but still clickable. Whenever I click the buttons, an active class will be added.
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default disabled">
<input type="radio" class="toggle" value="0" disabled="disabled">NO
</label>
<label class="btn btn-default disabled">
<input type="radio" class="toggle" value="1" disabled="disabled">YES
</label>
</div>
What am I doing wrong? Is it possible to disable the buttons?
For demo find below link of jsfiddle
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary disabled">
<input type="radio" autocomplete="off"> Radio 1 (pre-checked)
</label>
<label class="btn btn-primary active disabled">
<input type="radio" autocomplete="off"> Radio 2
</label>
<label class="btn btn-primary disabled">
<input type="radio" autocomplete="off"> Radio 3
</label>
</div>
Demo
The disabled attribute on the input will disable it, as in, you cannot change the value of the input while it's disabled. What you're seeing are the CSS stypes added by bootstrap that make it sorta look like something changed when you remove your mouse from the input.
You can prevent these styles with a little bit of jQuery:
$(".btn.disabled").mouseout(function(){
$(this).removeClass("active");
$(this).addClass("disabled");
});
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<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"/>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default disabled">
<input type="radio" class="toggle" value="0" disabled>NO
</label>
<label class="btn btn-default disabled">
<input type="radio" class="toggle" value="1" disabled>YES
</label>
</div>

With Bootstrap, how do I show radio inputs as buttons?

My form currently contains this code:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<label for="opt-0"><input type="radio" name="opt" id="opt-0" checked>Option 0</label>
<label for="opt-1"><input type="radio" name="opt" id="opt-1">Option 1</label>
<label for="opt-2"><input type="radio" name="opt" id="opt-2">Option 2</label>
Instead of showing the radio buttons as radio buttons, I'd like to make them look like regular buttons, like this:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<button class="btn btn-primary">Option 0</button>
<button class="btn btn-default">Option 1</button>
<button class="btn btn-default">Option 2</button>
I have radios and I want to make them look like toggleable buttons. How am I supposed to do that with Bootstrap?
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="options" id="option1"> Option 1
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2"> Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option3"> Option 3
</label>
</div>
Bootstrap 4 now offers a toggleable button group that manages the active state for you on click.
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-primary active">
<input type="radio" name="options" id="option1" autocomplete="off" checked> Active
</label>
<label class="btn btn-outline-primary">
<input type="radio" name="options" id="option2" autocomplete="off"> Radio
</label>
<label class="btn btn-outline-primary">
<input type="radio" name="options" id="option3" autocomplete="off"> Radio
</label>
</div>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="checkbox" autocomplete="off" checked> Checkbox 1 (pre-checked)
</label>
<label class="btn btn-primary">
<input type="checkbox" autocomplete="off"> Checkbox 2
</label>
<label class="btn btn-primary">
<input type="checkbox" autocomplete="off"> Checkbox 3
</label>
</div>
jsfiddle-link
getbootstrap
You could try looking at button groups, this is a goup of - well- buttons... which is toggleable like a radiobutton.
JSFiddle
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/js/bootstrap.min.js"></script>
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
Hope this helps!

How to change active color of bootstrap button group to have different color for each button

When I press the No button I want it to turn red. I want the Yes button to behave the way it already does ie. limegreen when active. How do I do this?
Please see my fiddle
html
<div class="col-sm-5 btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input checked="checked" name="media_release" value="1" type="radio"> Yes
</label>
<label class="btn btn-info active">
<input name="media_release" value="0" type="radio"> No
</label>
</div>
css
.btn-info.active {
background-color: limegreen;
}
.btn-info.active {
background-color: limegreen;
}
.btn_red.active {
background-color: red;
}
<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/2.1.1/jquery.min.js"></script>
<div class="col-sm-5 btn-group" data-toggle="buttons">
<label class="btn btn-info">
<input checked="checked" name="media_release" value="1" type="radio"> Yes
</label>
<label class="btn btn-info btn_red">
<input name="media_release" value="0" type="radio"> No
</label>
</div>

Select radio button by default using Bootstrap

Preselecting a radio button in twitter's bootstrap without using jquery.
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="radio" name="options" id="athletebutton" value="1" checked> Athlete </label>
<label class="btn btn-primary">
<input type="radio" name="options" id="coachbutton"> Coach </label>
</div>
Mark the label class with active
See screenshots & video here:
Video:http://d.pr/v/b3Gm
Screenshot: