I need to increase the space between the labels (which overlap with my resized radio buttons) and the radio buttons. The code snippets I have found only address the labels being to the left or right of the button. My labels are above the radio button, and now the two line labels (like "neither dislike or like", which spans two lines) are getting overlapped by the radio button. Thank you!
a screenshot of my radio buttons
Add this javascript to your Qualtrics question:
Qualtrics.SurveyEngine.addOnload(function()
{
var qid = this.questionId;
var radioCells = $(qid).select('td.ControlContainer');
var limit = radioCells.length;
for(i=0;i<limit;i++) {
radioCells[i].style.paddingTop = "25px";
}
});
Adjust the "25px" as necessary. You should consider upgrading to the new Qualtrics themes where the radio buttons go away and the labels become clickable buttons.
jsfiddle
As I am not sure if you are using bootstrap or any other layout framework, here is a solution with a simple table layout.
td {
width:100px;
text-align: center;
}
<!--EMMET string table>(tr>(td>label[for=radio$]{myradio$})*5)+(tr>(td>input#radio$[type='radio'][name=myradio])*5)-->
<table>
<tr>
<td><label for="radio1">myradio1</label></td>
<td><label for="radio2">myradio2</label></td>
<td><label for="radio3">myradio3</label></td>
<td><label for="radio4">myradio4</label></td>
<td><label for="radio5">myradio5</label></td>
</tr>
<tr>
<td><input type="radio" id="radio1" name="myradio"></td>
<td><input type="radio" id="radio2" name="myradio"></td>
<td><input type="radio" id="radio3" name="myradio"></td>
<td><input type="radio" id="radio4" name="myradio"></td>
<td><input type="radio" id="radio5" name="myradio"></td>
</tr>
Related
I have one table in my web page. It has column headers as well as row headers. In every cell there is a checkbox. It's not possible to provide visual labels to all the check boxes, so I am providing the labels using 'aria-label' property.
When I am navigating using the table shortcut keys (Alt+Ctrl+Arrow keys) the screen reader is announcing- row headers, column headers and 'aria-label' text.
Eg.'Action 1 checkbox not checked select action 1 for all event column 2', which is redundant.
So if I remove both the table headers, screen reader will announce only 'aria-label' text, which is meaningful and enough to identify the purpose of the checkbox. But as per the WCAG guideline(1.3.1 Info and relationship) table must have header associated with the table data.
So here are my questions:
If I remove the table headers-
Will it violate the WCAG compliance?. What is the interaction of the screen reader users with table?, Do they always need headers for navigation?. Will the screen reader users be able to complete the table activity by hearing 'aria-label' text only?.
Please see the code snippet:
<table>
<tr>
<th scope="col" width="40%">Events</th>
<th scope="col" align="left">Action 1</th>
<th scope="col" align="left">Action 2</th>
<th scope="col" align="left">Action 3</th>
</tr>
<tr>
<th scope="row">Select All</th>
<td><input type="checkbox" name="Action11" id="Action11" aria-label="Select action 1 for all event" /></td>
<td><input type="checkbox" name="Action12" id="Action12" aria-label="Select action 2 for all event" /></td>
<td><input type="checkbox" name="Action13" id="Action13" aria-label="Select action 3 for all event" /></td>
</tr>
<tr>
<th scope="row">Event 1</th>
<td><input type="checkbox" name="Action21" id="action21" aria-label="Select action 1 for event 1" /></td>
<td><input type="checkbox" name="Action22" id="action22" aria-label="Select action 2 for event 1" /></td>
<td><input type="checkbox" name="Action23" id="Action23" aria-label="Select action 3 for event 1" /></td>
</tr>
<tr>
<th scope="row">Event 2</th>
<td><input type="checkbox" name="Action31" id="action31" aria-label="Select action 1 for event 2" /></td>
<td><input type="checkbox" name="Action32" id="action32" aria-label="Select action 2 for event 2" /></td>
<td><input type="checkbox" name="Action33" id="Action33" aria-label="Select action 3 for event 2" /></td>
</tr>
</table>
Thanks in advance!
Keep the table headers. When navigating as a table (CTRL+ALT+arrows), the typical screen reader behavior is to only announce the header when a new row or column is reached, which is to prevent unnecessary repetition. However some things, such as announcing row and column numbers, can be customized by the user. Using aria-label here slightly begins to mess with those preferences by forcing repetitive speech.
Instead, use aria-labelledby to associate both the row and column headers with each checkbox as follows:
<table>
<tr>
<th scope="col" width="40%">Events</th>
<th id="a1" scope="col" align="left">Action 1</th>
<th id="a2" scope="col" align="left">Action 2</th>
<th id="a3" scope="col" align="left">Action 3</th>
</tr>
<tr>
<th id="sa" scope="row">Select All</th>
<td><input type="checkbox" name="Action11" id="Action11" aria-labelledby="sa a1" /></td>
<td><input type="checkbox" name="Action12" id="Action12" aria-labelledby="sa a2" /></td>
<td><input type="checkbox" name="Action13" id="Action13" aria-labelledby="sa a3" /></td>
</tr>
<tr>
<th id="e1" scope="row">Event 1</th>
<td><input type="checkbox" name="Action21" id="action21" aria-labelledby="e1 a1" /></td>
<td><input type="checkbox" name="Action22" id="action22" aria-labelledby="e1 a2" /></td>
<td><input type="checkbox" name="Action23" id="Action23" aria-labelledby="e1 a3" /></td>
</tr>
<tr>
<th id="e2" scope="row">Event 2</th>
<td><input type="checkbox" name="Action31" id="action31" aria-labelledby="e2 a1" /></td>
<td><input type="checkbox" name="Action32" id="action32" aria-labelledby="e2 a2" /></td>
<td><input type="checkbox" name="Action33" id="Action33" aria-labelledby="e2 a3" /></td>
</tr>
</table>
I agree with Adam. This table appears to be used for layout rather than for displaying structured tabular data.
There's nothing wrong with layout tables, but you should NOT use table heading <th> elements (use <td> instead), and remove all of your aria markup as well to avoid confusing screen-reader users. Use standard HTML form labels instead of the aria-labelledby attribute.
Putting additional data table markup (i.e. table headers, aria markup) would actually cause it to be less accessible, regardless of what any automated testing tools may tell you.
WebAIM has a pretty good explanation of layout tables vs. data tables, if you're interested in learning more about this subject.
http://webaim.org/techniques/tables/data
If I remove the table headers- Will it violate the WCAG compliance?
When you can consider that you are not displaying tabular data and use the table tag for layout purpose, WCAG lets you use a table tag for layout tables.. (as long as it can be linearized)
IMHO, what you are showing is a list of events with 3 actions. You may consider that it's not a data table.
In your case, the problem is that I don't see how, by removing table headers and without visual label for the checkboxes, you would help people without a screenreader know the intent of the checkboxes. aria-label is of no use for people not using a screenreader. WCAG require visual instructions.
Edit for clarity:
WCAG focuses mainly on data tables (where headings are required) but does not forbid layout tables (where headings are forbidden). All the question here is to understand if your table is really a data table or a layout table.
For instance, here, you could have used an ul list:
Events
<ul>
<li>Event 1
<input type="checkbox" title="Action1" aria-label="Action1" />
<input type="checkbox" title="Action2" aria-label="Action2" />
<input type="checkbox" title="Action3" aria-label="Action3" />
</li>
<li>Event 2
<input type="checkbox" title="Action1" aria-label="Action1" />
<input type="checkbox" title="Action2" aria-label="Action2" />
<input type="checkbox" title="Action3" aria-label="Action3" />
</li>
</ul>
And this makes me think that your table is not a data table, and that you use the table tag only for design for vertical alignment.
This is quite conceptual
EDIT 2: This alternative use of ul vs td (which is just to illustrate that you are not really using a data table) does not solve the problem of a visible label (also, curiously, this not a requirement in WCAG).
My opinion is that a visible label next to the checkbox is the best thing. If you can't, you have two options :
relying on javascript to display the title attribute when the field is focused
use small icons next to each checkbox (with correct alternative text which could be used to label the field)
This seems like it should be so basic but for the life of me I can't get it working.
In my MVC 5 web app, I would like to show the user a list of layouts using checkboxes so the user can select whichever layouts are required.
I'm using an editor template, that gets called as such:
<table class="table">
<tr>
<th>
#Html.DisplayName("Selected")
</th>
<th>
#Html.DisplayNameFor(x => x.Layout)
</th>
</tr>
#Html.EditorForModel()
</table>
Inside the template I use a helper for the checkbox.
<tr>
<td>
#Html.CheckBoxFor(x => x.IsSelected)
</td>
<td>
#Html.DisplayFor(x => x.Layout)
</td>
</tr>
This all works fine, I can capture what the user has selected in the Post
What I cannot do however is apply any CSS styles to the checkbox.
What I have read is it should be a matter of:
#Html.CheckBoxFor(x => x.IsSelected, new { #class = "css-checkbox" })
This however causes the checkbox to not be rendered.
I have tried a few things such as wrapping the checkbox in a
<div class="checkbox">
but even though the checkbox is rendered, I cannot select any of the items.
Now there is hopefully just something simple I am doing or not doing?
EDIT 1:
I seem to have come across the problem, but am not sure how to fix it.
If I use the following code, it works:
<input id="theid" name="theid" type="checkbox" class="css-checkbox" />
<label class="css-label" for="theid">Using input </label>
What I need to do is for the:
#Html.CheckBoxFor(x => x.IsSelected, new { #class = "css-checkbox" })
to be turned into the same as when I use input and label.
The page source looks as such:
<input checked="checked" class="css-checkbox" data-val="true" data-val-required="The IsSelected field is required." id="test5" name="IsSelected" type="checkbox" value="true" /><input name="IsSelected" type="hidden" value="false" />
<input id="theid" name="theid" type="checkbox" class="css-checkbox" />
<label class="css-label" for="theid">Using input </label>
The top comes from the helper and the bottom one is using the input tag directly.
My listbox is appearing differently in Chrome, Firefox and IE.
How can I make them look alike. I want 1px border
<asp:CheckBoxList ID="cbStatus" runat="server" RepeatColumns="4">
<asp:ListItem Text="Approved" Value="A"></asp:ListItem>
<asp:ListItem Text="Declined" Value="D"></asp:ListItem>
</asp:CheckBoxList>
Checkbox is one of those elements that will always render differently by different browsers. If you want the look to be unified I suggest one of jQuery plugins that turns ordinary checkboxes into styled controls.
For example your checkboxlist renders this HTML to browser:
<table id="cbStatus" border="0">
<tr>
<td><input id="cbStatus_0" type="checkbox" name="cbStatus$0" /><label for="cbStatus_0">Approved</label></td>
<td><input id="cbStatus_1" type="checkbox" name="cbStatus$1" /><label for="cbStatus_1">Approved w/ Requirements</label></td>
<td><input id="cbStatus_2" type="checkbox" name="cbStatus$2" /><label for="cbStatus_2">Declined</label></td><td></td>
</tr>
</table>
Using PrettyCheckable plugin you can issue a single command to style it::
$('input[type="checkbox"]').prettyCheckable();
And here is what it looks like after: http://jsfiddle.net/WuFg9/
You can adjust the styles to whatever you want, borders, colors etc. etc.
I have an asp:RadioButtonList named rblDependants
which renders as follows and a panel pnlDependants and I need to hide it when radio button selection is "No" and show it when its "Yes". I have tried a few snippets from the forums and none seem to work fine. Can anyone help me pls....!
<table id="ctl00_ContentPlaceHolder1_ctl02_rblDependants" border="0" style="border-width:0px;">
<tr>
<td><input id="ctl00_ContentPlaceHolder1_ctl02_rblDependants_0" type="radio" name="ctl00$ContentPlaceHolder1$ctl02$rblDependants" value="Yes" /><label for="ctl00_ContentPlaceHolder1_ctl02_rblDependants_0">Yes</label></td>
</tr><tr>
<td><input id="ctl00_ContentPlaceHolder1_ctl02_rblDependants_1" type="radio" name="ctl00$ContentPlaceHolder1$ctl02$rblDependants" value="No" checked="checked" /><label for="ctl00_ContentPlaceHolder1_ctl02_rblDependants_1">No</label></td>
</tr>
</table>
<div id="ctl00_ContentPlaceHolder1_ctl02_pnlDependants">
<div class="QuestionWrapper">
<div class="Question">
<label for="">No. of Dependants</label>
</div>
<div class="Answer">
<input name="ctl00$ContentPlaceHolder1$ctl02$txtNoOfDependants" type="text" maxlength="2" id="ctl00_ContentPlaceHolder1_ctl02_txtNoOfDependants" />
</div>
<div class="ClearFloat"></div>
</div>
Something like this should work:
$("table[id$=_rblDependants] :radio").change(function() {
$(this).closest('table').next().toggle(this.checked && this.value == 'Yes');
}).change();
This would work for any number of repeated controls since it finds the <div id="X_pnlDependants"> relatively. All we're doing it taking an <table> who's ID ends-with _rblDependants, taking any :radio buttons inside it and binding to their .change() event. Then either of them is changed it's checking that the result was value="Yes" and it was .checked, if that's the case show the panel, otherwise hide it, via .toggle(bool).
The .closest() and .next() are to go up to the <table> then to the next element, the <div>, since that's what you want to hide/show. The .change() on the end is to trigger the handler initially, so if "No" is initially checked, it hides the <div> on load.
You can give it a try here
I was wondering if any one could help me out; I have a table which looks something like the following:
<table id="Table1" border="0">
<tr>
<td><b>1.</b> Question 1</td>
</tr><tr>
<td style="border-width:5px;border-style:solid;"></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer1</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer2</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer3</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer4</label></td>
</tr><tr>
<td style="height:30px;"></td>
</tr><tr>
<td><b>2.</b> Question 2</td>
</tr><tr>
<td style="border-width:5px;border-style:solid;"></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio2" type="radio" name="Group2" value="Radio2" /><label for="Radio2">yes</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio2" type="radio" name="Group2" value="Radio2" /><label for="Radio2">no</label></td>
</tr><tr>
<td style="height:30px;"></td>
</tr>
</table>
How do I go about looping through each group of radio buttons and getting the text of the selected radio button?
The code displayed above is created dynamically ... in my aspx file I have the following code:
<asp:Table ID="Table1" runat="server">
</asp:Table>
If you want to access the rows in ASP.NET (on the server side), you need to convert the table, rows and the cells to server control (using runat="server") and iterate through the controls in the table.
EDIT : :- If you are adding the rows, cells and radionbuttons following way, all of them will be the server controls (and are runat=server) so that you can access them the way I mentioned above:--
// Create new row and add it to the table.
TableRow tRow = new TableRow();
table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
{
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
RadioButton rdb = new RadioButton();
rdb.ID = "rdb_" + cellCtr.ToString();
rdb.Text = "radio button";
rdb.GroupName = "rdbGroup";
tCell.Controls.Add(rdb);
tRow.Cells.Add(tCell);
}
EDIT:-
You can find the controls in each cell.Something like below:-
foreach(TableCell cell in tableRow.Cells)
{
foreach(Control ctrl in cell.Controls)
{
if(ctrl is RadioButton)
{
if(ctrl.Selected)
{
string rdValue=ctrl.Text;
}
}
}
}
Or If you want to iterate on the client side using Javascript, have a look here and you dont have to apply runat="server".
It sounds like you're starting with a barebones <table> in your markup page, and dynamically adding those <input> afterwards.
Consider taking this approach:
Add the runat="server" attribute to your table.
In the code where you're adding those <input> tags, add a new RadioButton control. Use an ID here that you can predict later. Perhaps you can use a RadioButtonList instead, if the choices are logically grouped!
It's unclear if you're manually adding those <tr> and <td> as strings. Consider the option of new TableRow() and new TableCell(). Then add the new RadioButton to the TableCell.Controls collection with tc.Controls.Add(myNewRadioButton);
In your postback code, simply refer to your RadioButton controls by id, or even loop through the Controls collection property of the Table1.
foreach (Control x in Table1.Controls)
{
if (x.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButton"))
{
if (((RadioButton)x).Checked)
{
//proceed.
}
}
}
Convert all controls to server controls (by adding the runat="server" attribute). You can then programatically access what you need o. The server.