In my project there is 2 radio buttons on checkout page with options: Pickup Radio Button & Shipping Radio Button
.
When user selects Pickup option. Then, it shows pickup locations (stored in custom table). And when user selects ship option. It shows woocommerce "Ship to a different address?" options.
Now, I want to remove shipping charges via AJAX if user selects "Pick up?" option. And re-add shipping charges if user selects "Ship?" option.
Please help me out.
Finally I reached to the solution.
I have set to shipping metthod (store pickup & local delivery). And hiding the unchecked shipping method. Once customer changed the option (clicked on custom radio buttons) ie Pickup Radio Button & Shipping Radio Button. On Pickup radio button checked I am setting store pickup shipping method to checked and triggering the jquery function that runs ajax and updating the cart total & shipping amount. And on another end I am hidding the local delivery shipping method radio button. And same is happening with vice versa.
Style.css
.woocommerce ul#shipping_method li input {
position: absolute; left: -25px;
}
.woocommerce ul#shipping_method li {
margin: 0; overflow: hidden; padding: 0; position: relative;
text-indent: 0; display: none;
}
.woocommerce.pickup ul#shipping_method li:first-child {
display: block;
}
.woocommerce.ship ul#shipping_method li:last-child {
display: block;
}
jQuery
$('[name="order_type"]').on("change",function(){
/* Pickup Radio Button / Shipping Radio Button ?*/
showHideOrderTypeOptions();
});
function showHideOrderTypeOptions()
{
var order_type = $('[name="order_type"]:checked').val();
if(order_type == "Ship")
{
$(".shipping_address, #ship-to-different-address").show();
$(".store-locations-wrapper").hide();
$("#store_address_id").val("");
$("#ship-to-different-address-checkbox").attr("checked",true);
$('[name="store_address"]').attr("checked",false);
$(".woocommerce").removeClass('pickup').addClass("ship");
$("#shipping_method li").eq(1).find("input").trigger("click");
}
else
{
$(".shipping_address, #ship-to-different-address").hide();
$(".store-locations-wrapper").show();
$("#ship-to-different-address-checkbox").attr("checked",false);
$(".woocommerce").removeClass('ship').addClass("pickup");
$("#shipping_method li").eq(0).find("input").trigger("click");
}
}
woocommerce >> form-billing.php
<div class="order-type-wrapper">
<h3>Order Type - </h3>
<input id="order-type-pickup" class="input-radio" <?php checked( $order_type, 'Pickup' ); ?> type="radio" name="order_type" value="Pickup" />
<label for="order-type-pickup" class="radio"><?php _e( 'Pick up?', 'woocommerce' ); ?></label>
<input id="order-type-ship" class="input-radio" <?php checked( $order_type, 'Ship' ); ?> type="radio" name="order_type" value="Ship" />
<label for="order-type-ship" class="radio"><?php _e( 'Ship?', 'woocommerce' ); ?></label>
</div>
<div class="store-locations-wrapper">
<input type="hidden" id="store_address_id" name="store_address_id" value="<?php echo $store_address_id; ?>" />
<h3>Pickup Location</h3>
Store locations goes here.
</div>
Related
I have this piece of HTML which is updated dynamically with JS. The screen reader only reads out the new value when they get updated. It doesn't say the label of the input who was updated.
<ul class="points-transfer-detail-points-calculation clearfix">
<li>
<label for="points-to-transfer">{{{ pointsToTransferLabel }}}</label>
<input id="points-to-transfer" type="text" aria-controls="brand-points points-left-after-transfer" placeholder="XXX,XXX" {{#if disabled }}disabled{{/if}}>
<p id="points-to-transfer-error" class="points-transfer-detail-form-error" aria-hidden="true" role="alert">{{{ pointsToTransferErrorMessage }}}</p>
</li>
<li>
<label for="brand-points">{{{ brandPointsLabel }}}</label>
<input id="brand-points" type="text" aria-live="polite" aria-atomic="true" disabled>
</li>
<li>
<label for="points-left-after-transfer">{{{ pointsLeftLabel }}}</label>
<input id="points-left-after-transfer" type="text" aria-live="polite" aria-atomic="true" disabled>
</li>
</ul>
I have tried to use aria-labelledby, aria-describedby, role="alert" and aria-label but no results, only the value of the input and never his label.
From all my research on Google and StackOverflow, I didn't manage to found a proper answer.
I'm using NVDA in Firefox as a screen reader.
Thank you for your help.
The only time a label should be read by a screen-reader is when focus is placed on its corresponding field.
Your input fields are all disabled. Therefore the labels wouldn't be read since you can't focus into the fields.
Remove your aria-live and aria-atomic from your input fields. They are unusable on input fields. Aria-live is triggered on DOM change within the container it's assigned to. An input field is not a container. Also, labels shouldn't be announced that way anyway.
If you want to announce a change to the DOM I would suggest injecting content into an empty aria-live div at the bottom of your page and hide it accessibly.
Here is a working example with one static label and 3 dynamic labels. One uses the "disabled" attribute, and one uses aria-disabled so that it can still receive focus. An announcement about the rendering of the new labels is also featured using an accessibly-hidden aria-live container.
This has been tested in NVDA in FF, JAWS in IE, and VO in Safari.
(function () {
function populateLabels () {
document.querySelector('[for="dogsName"]').appendChild(document.createTextNode('Dog\'s Name'));
document.querySelector('[for="catsName"]').appendChild(document.createTextNode('Cat\'s Name'));
document.querySelector('[for="lastName"]').appendChild(document.createTextNode('Last Name'));
}
function announceChange () {
var announcement = "Some new labels have appeared. They are Last Name, Dog's Name, and Cat's Name.",
ariaLiveContainer = document.querySelector('[aria-live]');
ariaLiveContainer.appendChild(document.createTextNode(announcement));
setTimeout(function () {
ariaLiveContainer.innerHTML("");
}, 2000);
}
setTimeout(function () {
populateLabels();
announceChange();
}, 3000);
}());
input {
border: 1px solid black;
}
[disabled],
[aria-disabled="true"] {
border: 1px solid #ccc;
background-color: #eee;
}
.acc-hidden { /* Hide only visually, but have it available for screenreaders */
position: absolute !important;
display: block;
visibility: visible;
overflow: hidden;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
clip: rect(0 0 0 0);
}
<p>The first label is there on DOM load. The other three labels come in 3 seconds after DOM load. An announcement is made about the updated labels.</p>
<form action="">
<ul>
<li>
<label for="firstName">First Name</label>
<input type="text" name="first-name" id="firstName" />
</li>
<li>
<label for="lastName"></label>
<input type="text" name="last-name" id="lastName" />
</li>
<li>
<label for="dogsName"></label>
<input type="text" name="dogs-name" id="dogsName" disabled /> (uses the disabled attribute -- doesn't receive focus)
</li>
<li>
<label for="catsName"></label>
<input type="text" name="cats-name" id="catsName" aria-disabled="true" /> (uses the aria-disabled="true" attribute -- can receive focus)
</li>
</ul>
</form>
<div class="acc-hidden" aria-live="polite"></div>
Using opencart version 2.0.0
Within the Product.tpl page there is a foreach option loop that contains this
<?php if ($option['type'] == 'image') { ?>
<div class="form-group<?php echo ($option['required'] ? ' required' : ''); ?>">
<label class="control-label"><?php echo $option['name']; ?></label>
<div id="input-option<?php echo $option['product_option_id']; ?>">
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<div class="radio">
<label>
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" />
<img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" class="img-thumbnail" /> <?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</label>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
Which is all fine and working. But what i want to know, is, I see that they've wrapped the Input in a Label class. Because this is an image select, I can have a small 50px image of a colour, to select an option, and you can click on the image itself as opposed to clicking on the radio button to select it.
what i want to know is, using the jsfiddle i've made http://jsfiddle.net/8fqqrstq/ I want to remove the radio button itself using
input[type="radio"] { visability: hidden; }
But people still click on the image to select that option. BUT!, Whe the option is selected, a :checked css is used to change the border of the image to say
border: solid 1px #ff0000
How would i go about doing this?
I don't have enough reputation to comment, but I was having the same problem and wanted to post a jsfiddle link to show what you were trying to do in case someone else was a bit confused on it!
The only thing changed is that I removed the text next to each option and gave each radio button the same name so that only one could be selected! I also used
display:none;
instead of
visibility: hidden;
for the radio buttons so that extra space isn't taken up.
This is the CSS that shows how to use images as options without showing the radio button too.
div.radio img { border: solid 1px #bbb; padding: 2px; }
div.radio label { font-family: arial; }
input[type=radio]{ display: none; }
input[type=radio]:checked + img { border: solid 1px #ff0000; }
I'm importing a mailing list into MailChimp and am having trouble with implementing interest groups correctly. Here's my situation: subscribers have opted in to receive updates for one or more geographic area (NYC, Boston, etc.) The vast majority of users belong to only one group, but it's important to allow people to sign up for more than one group. MailChimp groups work for this perfectly, EXCEPT for the fact that groups can't be made required fields...except using the advanced form design mode.
Per the Mailchimp documentation:
Group fields can not be set to required for a sign up form. The logic in our database is such >that Groups shouldn't be required because they are considered to be a list of options or >interests for segmenting and it is valid for someone to have no interests. If you are an >?>advanced user or have a developer that can help out, a required Groups field could be custom >coded using the Advanced forms option(available only to paid accounts) in your account.
I've done a ton of searches to find even the first steps to addressing this through the advanced form mode but have come up empty so far. I'm no expert on HTML/Javascript/PHP but I know enough to tinker and get things done through trial and error. Also, the form will ideally be hosted on a WordPress page.
I have experienced same problem with you.
What i did is added a javascript validation to the Mailchimp embed code.
This is the example of the code. I was using radio buttons.
I'll just remove the form action button for personal reasons
<!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; width:650px;margin:auto;}
.mc-field-group{width:50% !important;margin:auto;}
.mc-field-group.input-group{width:96% !important;margin:auto;}
#mc-embedded-subscribe{
margin: auto;
width: 150px !important;
height: 30px !important;
font-size: 15px !important;
background: #eb593c !important;
position: relative !important;
color: #fff !important;
margin-left: 38% !important;
}
/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
<label for="mce-EMAIL">Email Address <span class="asterisk">*</span>
</label>
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
<label for="mce-FNAME">First Name </label>
<input type="text" value="" name="FNAME" class="" id="mce-FNAME">
</div>
<div class="mc-field-group input-group">
<strong>How Often Would You Like to Hear From Us: <span class="asterisk">*</span></strong>
<ul><li><input type="radio" value="4" name="group[10709]" id="mce-group[10709]-10709-0"><label for="mce-group[10709]-10709-0">Somewhat Weekly: THRIVING IS THE NEW YOU Blog Posts sent via Email</label></li>
<li><input type="radio" value="8" name="group[10709]" id="mce-group[10709]-10709-1"><label for="mce-group[10709]-10709-1">Monthly Vibrancy Roundup: It's like a E-Newsletter but way groovier.</label></li>
</ul>
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_ef38bee7ba91bb0815db87917_22d8d62dc8" tabindex="-1" value=""></div>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
</form>
<script type="text/javascript">
var forms = document.getElementById('mc-embedded-subscribe-form');
try {
forms.addEventListener("submit", function(event)
{
var off_payment_method = document.getElementsByName('group[10709]'); //this is the name of the radio buttons
var email = document.getElementById('mce-EMAIL');//email field
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
event.preventDefault();
return false;
}
var ischecked_method = false;
for ( var i = 0; i < off_payment_method.length; i++) {
if(off_payment_method[i].checked) {
ischecked_method = true;
}
}
if(!ischecked_method){
alert("Please choose from How Often Would You Like to Hear From Us:");
event.preventDefault();
return false;
}else{
return true;
}
}, false);
} catch(e) {
forms.attachEvent("onsubmit", function(event)
{
var off_payment_method = document.getElementsByName('group[10709]'); //this is the name of the radio buttons
var email = document.getElementById('mce-EMAIL');//email field
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
event.preventDefault();
return false;
}
var ischecked_method = false;
for ( var i = 0; i < off_payment_method.length; i++) {
if(off_payment_method[i].checked) {
ischecked_method = true;
}
}
if(!ischecked_method){
alert("Please choose from How Often Would You Like to Hear From Us:");
event.preventDefault();
return false;
}else{
return true;
}
}); //Internet Explorer 8-
}
</script>
</div>
<!--End mc_embed_signup-->
Have you tried adding class="required" to each group field in the advanced editor? When I look at my required fields, they are declared with this class (except the email, which seems to have a special "email required" class:
<div class="mc-field-group"><label for="mce-FNAME">First Name <span class="asterisk">*</span>
</label>
<input class="required" id="mce-FNAME" type="text" name="FNAME" value="" /></div>
<div class="mc-field-group"><label for="mce-LNAME">Last Name </label>
<input id="mce-LNAME" type="text" name="LNAME" value="" /></div>
In this example, taken from one of my forms (hosted on a WP page), FNAME is required, but LNAME is not.
I am looking for a way to override the checked (x) style in a foundation for custom checkbox
Following the custom forms documentation I have successfully implemented a custom checkbox as follows:
<form class="custom">
<label for="checkbox1">
<input type="checkbox" id="checkbox1" CHECKED />
<span class="custom checkbox checked"></span>Label for checkbox 1
</label>
</form>
This allows me to make css style changes to the look of the checkbox, but I can't find a way te effect the x itself.
if you look in the CSS file used on the page you link to, you will find this part, that is styling the checked checkbox:
form.custom .custom.checkbox.checked:before {
content: "\00d7";
color: #222222;
position: absolute;
top: -50%;
left: 50%;
margin-top: 4px;
margin-left: -5px;
}
changing the content will change the symbol displayed. Hope this helps.
DEMO (provided in Andrey's comment)
change the value of content in your css
form.custom .custom.checkbox.checked:before {
content: "×00d7";}
to
form.custom .custom.checkbox.checked:before {
content: "*";}
or what ever you want
Try this code which would change the "x" to true sign
form.custom .custom.checkbox.checked:before {
content: "\2714";}
Is it possible to create a radio button group without the round buttons in front of each element?
The reason I would like to implement this is, that in my case the user has to choose between 3 different languages and I would really like to add this selection to a <form> tag, change the color of the selected language and make it required, but in the same time I wanted it to look something like this:
___________________________
| Username | <--Text input
___________________________
___________________________
| Password | <--Text input
___________________________
____________________________
| EN | DE | FR | <--This is what I thought of... Horizontal selection
____________________________ of the language looking like a simple table with
3 rows and the plain text (EN, DE, FR) in it.
____________________________
| Login | <--Submit button
____________________________
I really hope that you're able to get my point :)
If you put the radio buttons inside the labels and then make them invisible the user can click the label to select the radio button that is inside it. Consider the following approach.
HTML:
<div>
<label><input type="radio"/>English</label>
<label><input type="radio"/>French</label>
</div>
CSS:
label > input[type=radio] {
visibility: hidden;
}
JSFiddle here: http://jsfiddle.net/gEXUT/
Note that this is just an example, you'd still need to add the radio group name and perhaps the option for German etc.
Yes and no.
If you build your form with input and labels, it will do, else,
you have to. :)
the idea is :
input[type=radio] {
position:fixed;
left:-9999px;
}
As being fixed and of the screen, your input radio won't be in the flow anymore.
If labels are well formed and link to theme with attribute for, you just need to clikc the label to checked your invisible radio input.
To style your form, don't mind those imputs, style your labels as wished.
<input type="radio" name="r-lang" id="r1"><label for="r1"> EN </label>
Cheers
I've actually written on this before, and made a jsfiddle example:
http://jsfiddle.net/Kyle_Sevenoaks/HzQBE/
I'll explain it though. (I've put the labels an radio buttons into a list for this example)
<li class="cardtype-item">
<input type="radio" name="preferred_color" id="red" value="Red" />
<label for="red"> Red</label>
</li>
The general idea is that you have labels linked to the radio buttons, but the radios are hidden (either by display, position, etc). Then you use CSS to style the labels exactly as you like, and because they're linked to the radio buttons (via "name" on the input and "for" on the label) you can have much more control over how they look.
li
{
background: #333;
color: #eee;
padding: 10px;
list-style-type: none;
float: left;
width: 100px;
}
li.selected
{
background: #eee;
color: #333;
box-shadow:inset 0px 0px 15px #999;
}
input[type=radio]
{
display: none;
}
The next part of the trick is to use Javascript (I've use jQuery) to add and remove the selected or active class on the label itself.
$('li.cardtype-item label, li.cardtype-item input').click( function() {
$(this).parents('li').addClass('selected');
$(this).parents().siblings('li').removeClass('selected');
});
var ident = $('input[type=radio]').attr("id");
if($('input[type=radio]').is('checked')) {
$('form').append(ident);
};
I hope this gives you pretty much what you're after.
try this
radio button html
<div class="buttonSlider">
<input type="radio" value=".." name="radio1" />
<input type="radio" value=".." name="radio1" />
<input type="radio" value=".." name="radio1" />
</div>
javascript
$(document).ready(function () {
$('.buttonSlider input').replaceWith('<div class="radiobox"> <input type="radio" name="radio1" value=".."/></div>');
$('.buttonSlider input').prop('checked', false);
$('.radiobox').click(function () {
var this_div = $(this);
if (this_div.find('input').is(':checked')) {
this_div.find('input').prop('checked', false);
this_div.css({ 'background-color': '#800001' });
}
else {
this_div.find('input').prop('checked', true);
this_div.css({ 'background-color': '#808080' });
}
})
})
css
.buttonSlider
{
background-color: #800001;
}
.buttonSlider .radiobox
{
height: 20px;
width: 100px;
border: 1px solid black;
background-color: #800001;
float: left;
}
.buttonSlider input
{
display: none;
}
Thanks to the help of everyone of you (and this awesome answer). I could finally implement it in my website.
This is my code:
HTML:
<div id="language">
<table id="languagetable" border="0px" cellspacing="0px">
<tr>
<td width="33.33333%">
<input type="radio" id="fr" name="languageselection" value="en">
<label for="en">FR</label>
</td>
<td width="33.33333%">
<input type="radio" id="en" name="languageselection" value="de" checked>
<label for="de">EN</label>
</td>
<td width="33.33333%">
<input type="radio" id="it" name="languageselection" value="it">
<label for="de">DE</label>
</td>
</tr>
</table>
</div>
CSS:
#languagetable input[type="radio"] {
display:none;
}
#languagetable label {
display:inline-block;
margin: 0 auto;
font-family: Arial;
font-size: 20px;
}
#languagetable input[type="radio"]:checked + label {
color: #99CC00;
}