I'm new at coding and I must be making a simple mistake that I can't figure out.
My angular aplications has two Modals, the first is a form to add and the second is the edit.
When I'm using the first modal the radio button works, but when I try the second the radio buttons wont work. As if they were disabled.
One thing that I've noticed is that when I use the tab button on my keyboard the radio buttons are selectable through the keyboard.
I've also noticed that if I change the code of the modal that has the radio button that was not working before the code that was working this inverts the issue.
The code that is "rendered" first works.
<!-- fist RadioButton -->
<div class="md-form">
<div class="d-flex justify-content-around">
<p>Tipo da Instituição: </p>
<div class="custom-control custom-radio custom-control-inline">
<input formControlName="tipoedit" type="radio" class="custom-control-input" id="publica" name="tipoedit"
value="Publica">
<label class="custom-control-label" for="publica">Publica</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input formControlName="tipoedit" type="radio" class="custom-control-input" id="privado" name="tipoedit"
value="Privado">
<label class="custom-control-label" for="publica">Privado</label>
</div>
</div>
<div *ngIf="submitted && fedit.type.errors" class="invalidFeedback">
<div *ngIf="fedit.type.errors.required">Tipo é obrigatorio</div>
</div>
</div>
<!-- Second RadioButton -->
<div class="md-form">
<div class="d-flex justify-content-around">
<p>Tipo da Instituição: </p>
<div class="custom-control custom-radio custom-control-inline">
<input formControlName="tipo" type="radio" class="custom-control-input" id="publica" name="tipo"
value="Publica">
<label class="custom-control-label" for="publica">Publica</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input formControlName="tipo" type="radio" class="custom-control-input" id="privado" name="tipo"
value="Privado">
<label class="custom-control-label" for="privado">Privado</label>
</div>
</div>
<div *ngIf="submitted && fadd.tipo.errors" class="invalidFeedback">
<div *ngIf="fadd.tipo.errors.required">Tipo é obrigatorio</div>
</div>
</div>
The problem seems to be your for attributes on the labels and the fact that you have multiple elements with the same ids. I highly recommend never having two HTML elements with similar ids.
Try changing the ids of your second radio modal (something like privadoEdit/publicaEdit )and change the for attributes accordingly.
Also, your first modal has publica in both your label's for attributes, change the second one to privado
Hope this hleps
Related
I have some custom radio buttons. The final option should be a radio button with an input field.
As you can see, in de Codepen example, the radio button does not align vertically center with the input field.
I have tried everything from calculating top, to display flex.
Codepen: https://codepen.io/monsmado/pen/RwarYEG
<form>
<label>Do you have an elevator?</label>
<div class="custom-control custom-radio">
<input type="radio" id="elevatorYes" name="elevator" class="custom-control-input">
<label class="custom-control-label" for="elevatorYes">Yes</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" id="elevatorNo" name="elevator" class="custom-control-input">
<label class="custom-control-label" for="elevatorNo">No</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" id="elevatorOther" name="elevator" class="custom-control-input">
<label class="custom-control-label" for="elevatorOther">
<input type="text" class="form-control" name="elevator" placeholder="Other">
</label>
</div>
</form>
Add this CSS in this case
.form-group:nth-child(4) .custom-control-label:after, .form-group:nth-child(4) .custom- control-label:before{
margin-top: 0.5em
}
I send you the solution in you codepen
https://codepen.io/r0binxp/pen/qBZbJaZ
Well, a quick fix for your situation could be overriding the current top value of the custom radio button and set it to 25% (Since the actual height of it is 50% of your input so the 25% will fit it exactly in middle). Also, note that display flex on the parent element won't work as expected because the customized radio exits within the ::before pseudo-element so it won't get the flex attribute.
.custom-control-label[for=monthsOther]::before,
.custom-control-label[for=monthsOther]::after {
top: 25%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<form>
<label>How many months?</label>
<div class="custom-control custom-radio">
<input type="radio" id="monthsYes" name="months" class="custom-control-input">
<label class="custom-control-label" for="monthsYes">1-2</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" id="monthsNo" name="months" class="custom-control-input">
<label class="custom-control-label" for="monthsNo">3-5</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" id="monthsOther" name="months" class="custom-control-input">
<label class="custom-control-label" for="monthsOther">
<input type="text" class="form-control" name="months" placeholder="Other">
</label>
</div>
</form>
NOTE: Keep in mind since the radio button itself and its background on check action is defined in ::before and ::after pseudo-elements you need to override both of them.
This seems like a really hacky way to change the appearance of form elements. The original question is missing any CSS code (which is where all the problems arise) but the linked codepen does show the root causes. It will be very difficult to properly align elements that are absolutely positioned, especially when you start taking left-to-right or larger font sizes into account. Additionally, creating the visual representation of a radio button using a ::before on inside the label is a recipe for frustration and ultimately a bad solution.
The proper solution is probably using vertical-align: middle or vertical-align: baseline on both the radio and the label. but those will have no effect while the elements are absolutely positioned.
I have a couple of checkbox that I would like to make only one of them clickable. I have tried different solutions on stack overflow. I also changes changed the input type to radio and I have used the following code but still its not working:
$(document).ready(function () {
$('input[type=radio]').change(function() {
// When any radio button on the page is selected,
// then deselect all other radio buttons.
$('input[type=radio]:checked').not(this).prop('checked', false);
});
});
My Code is as follows:
<div id="options-content5" class="collapse">
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox15" type="checkbox" name="last24">
<label for="checkbox15">
Last 24 Hours
</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox16" type="checkbox" name="last3Days">
<label for="checkbox16">
Last 3 days
</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox17" type="checkbox" name="last7Days">
<label for="checkbox17">
Last 7 days
</label>
</div>
<br>
</div>
If you want to make only one of a set of checkboxes clickable, use radio buttons with the same name. This will be much better for usability and accessibility. Here's an article from the Nielsen Norman Group about how to choose between checkboxes and radio buttons and why it matters. https://www.nngroup.com/articles/checkboxes-vs-radio-buttons/
I'd recommend using the values in place of your names to differentiate.
<div id="options-content5" class="collapse">
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox15" type="radio" name="lastTimeFrame" value="last24">
<label for="checkbox15">Last 24 Hours</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox16" type="radio" name="lastTimeFrame" value="last3Days">
<label for="checkbox16">Last 3 days</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox17" type="radio" name="lastTimeFrame" value="last7Days">
<label for="checkbox17">Last 7 days</label>
</div>
<br>
</div>
I built a custom radio button using this structure. However using this configuration I cant click the text to toggle the radio, any ideas why this is not working?
<div class="form-group">
<label class="custom-control custom-radio">
<input id="pefrormanceRadio" name="bonusRangeRadio" type="radio" class="custom-control-input" value="pefrormanceRadio">
<span class="custom-control-indicator"></span>
</label>
<span class="custom-control-description">test</span>
</div>
You can achieve this by moving your text inside the label element.
Clicking a label will also click its associated form input. You can either associate a label and a form input with the 'for' HTML attribute (as per zmuci's answer) or by wrapping your input with the label element (which you are already doing).
In your case you were trying to click some text that was outside the label (hence not associated in any way with the input).
<div class="form-group">
<label class="custom-control custom-radio">
<input id="pefrormanceRadio" name="bonusRangeRadio" type="radio" class="custom-control-input" value="pefrormanceRadio">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">test</span>
</label>
</div>
You need to "connect" the text and input, you do that with for attribute added to label tag.
So your HTML should look something like this:
<div class="form-group">
<input id="pefrormanceRadio" name="bonusRangeRadio" type="radio" class="custom-control-input" value="pefrormanceRadio">
<label class="custom-control custom-radio" for="pefrormanceRadio">Test</label>
<span class="custom-control-indicator"></span>
</div>
Or if you can't change the HTML, Den Biswajit answer is the correct one. But you should be aware that from the semantic/accessible point of view, input should have a meaningful label.
Please add custom-control-description inside label and update css
<div class="form-group">
<label class="custom-control custom-radio">
<input id="pefrormanceRadio" name="bonusRangeRadio" type="radio" class="custom-control-input" value="pefrormanceRadio">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">test</span>
</label>
</div>
you can do this using jquery
$("label").click(function(){
$("#pefrormanceRadio").attr('checked', 'checked');
});
With Twitter Bootstrap 3.3.7, I am trying to line up multiple questions that have inline radio button answers and have the radio buttons for all questions line up to be displayed nicer for end users.
If this is on a Extra small device, I want the radio buttons to be on the next line.
The trouble I am having is that applying col-sm-6 (or any column size) seems to not work as I expect. The help-block doesn't fully go to the next line, it's stuck under the radio buttons.
I'm looking to be able to use proper Twitter Bootstrap form syntax. Is this possible with the form syntax, or does this require doing it with their own rows/cols?
An example of a question: JSFiddle https://jsfiddle.net/y8j5f0of/
<div class="row">
<div class="form-group">
<label class="col-sm-6">This is an example question</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
Answers are lined up, but the output isn't flowing properly.
If I remove the col-sm-6, everything flows as expected but the answers aren't lined up. Also, this doesn't allow the radio buttons to go to their own line for Extra small device.
JSFiddle https://jsfiddle.net/nz36k74o/1/
<div class="row">
<div class="form-group">
<label>This is an example question 1 that is longer than question 2</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
Output
The help block should really be in a new row. If it is supposed to be underneath the other content, then its not part of the row. That's the basis of the Bootstrap grid system. A basic question block should look like this:
<div class="form-group">
<div class="row">
<label class="col-sm-6">This is an example question 1 that is longer than question 2</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
</div>
Check out the fiddle (sorry onlyhad time to do one)
Here is one solution to align the question correctly. It adds in some extra html tags but I believe it solves your issue.
This is the updated fiddle.
https://jsfiddle.net/nz36k74o/3/
<div class="form-group">
<label class="col-sm-6">This is an example question</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<span class="help-block">This is an example help block.</span>
</div>
</div>
I would like to use these funky radio buttons though the radio buttons have an id=radio1, id=radio2, id=radio3 etc
I would like all of them to have id-radio1 so it writes the result to radio1 in the database:
Here is how I have normal radio buttons working in the past using the same id and they toggle between one another:
<div class="form-group col-md-12">
<label class="control-label form-check-inline">Gender</label>*
<div class="form-group">
<input type="radio" id="Gender" name="Gender" value="M" required="required" /><label class="control-label">Male</label>
<input type="radio" id="Gender" name="Gender" value="F" required="required" /><label class="control-label">Female</label>
</div>
</div>
$Gender=$_POST["Gender"];
INSERT INTO [dbo].[SubmissionsTBL]
[Gender]
VALUES
(,'".trimText($Gender)."')
Though, with the funky radio buttons chaning from this:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio2"/>
<label for="radio2">Female</label>
</div>
</div>
to this doesn't work - it doesn't allow me to toggle radio buttons:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1"/>
<label for="radio2">Female</label>
</div>
</div>
What is stopping the toggle?
Thank you!
TL;DR: Due to the id and name attribute having the same value in your first example, I believe you may be confusing the two. With the database communication code you put up, it's grabbing the name="Gender" and not the id="Gender".
Additional information about id and class though you might find useful as an internet programmer:
The id attribute can only apply to one element per HTML document. I would suggest using the class attribute instead. The main difference between and id and a class is that a class can be applied to multiple elements.
Here is a working solution to the code you provided:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio1" class="radio_grp1"/>
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio2" class="radio_grp1"/>
<label for="radio2">Female</label>
</div>
</div>
I used the class .radio_grp1 as the name so that you know that you're referring to a group of radio buttons rather than just one.
Moreover, if you're using a library like bootstrap, it's very common that an element will already have an assigned class. To solve this issue, you can assign a single element multiple classes by adding a space in the string following the class attribute like so:
<input type="radio" name="radio" id="radio2" class="radio radio_grp1"/>
Hope this was useful!
Your code should be changed to something like this. the radio button's name is what is submitted to the back end, and the id is used for front-end things like label association.
id's should always be unique.
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio2"/>
<label for="radio2">Female</label>
</div>
</div>
If by toggling, you mean the normal behavior of radio buttons, then that happens whenever all the radio buttons in the group have the same name.