Mailchimp - Make interest group a required field on sign up form - wordpress

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.

Related

ASP.Net Core MVC : How to use css after press button in the section of HTML.BeginForm

My code are below
#using (Html.BeginForm("PostUsingParameters", "loopW"))
{
<input type="text" name="num" /><br />
<input type="submit" value="Click Me" />
}
after pressing the button it jumps to the destination page but there is no any CSS effect to the result.
I have tried many ways including using FormMethod.Post new { #class = "example" }. Unfortunately, it’s no use to make the CSS take effect in the destination page. Would appreciate some advice on this problem.
I use .Net 5.0 in my project. Moreover, I want the CSS working on new page after pressing submit button.
<head>
...
<style>
.example {
font-size: 70px;
color: red;
}
</style>
</head>
<body>
<div>
<section>
#using (Html.BeginForm("PostUsingParameters", "loopW", FormMethod.Post, new { #class = "example" }))
{
<input type="text" name="num" /><br />
<input type="submit" value="Click Me" />
}
</section>
</div>
</body>

Aria-live doesn't say label after updates

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>

How to change background color of input once value is selected using AngularJS?

I have selected user from search in Js function currently input field is readOnly , So once we have value from selectedOwner i want to change input field background color to white because user don't want to see gray color that is coming from readOnly directive ? Is there way to implement this kind of requirement ?
main.html
<div class="form-group col-md-6">
<div class="col-md-6">
<label class="control-label required" for="rcsaOwner">RCSA
Owner :</label>
</div>
<div class="col-md-6">
<input type="text" class="form-control" id="rcsaOwner" required ng-class="{'background1': color.back}"
ng-model="riskAssessmentDTO.rcsaOwnerWorker" name="rcsaOwnerWorker"
ng-click="openRcsaOwner()" ng-model-options="{updateOn: 'blur'}" ng-readOnly="true"/>
<p class="text-danger"
ng-show="addAssessment.rcsaOwnerWorker.$touched && addAssessment.rcsaOwner.$error.required">RCSA
Owner is required</p>
</div>
</div>
mainCtrl.Js
$scope.selectedOwner = function (selectedOwner, workerKey) {
this.$parent.$parent.rcsaOwnerModal.close();
$scope.riskAssessmentDTO.rcsaOwnerWorkerKey = workerKey;
$scope.riskAssessmentDTO.rcsaOwnerWorker = selectedOwner;
$scope.color = { back: true};
};
main.css
.background1 {
background-color: #eeee12;
color: red;
}

How to update variables with input values in .less file dynamically using AngularJS

I realize a form of this question has been asked before (see 28208451), however, I need to get the input value and then set it as the new value so that other input fields can access it. Here is a link to my plunk.
I can enter a new hue but it is not saved when I attempt to change the saturation or lightness. I am sure it is an easy fix (possibly a directive) but for the life of me I cannot wrap my head around it. I am still fairly new at AngularJS ... any help would be appreciated.
**controller:**
angular.module('colorChanger', [])
.controller('ColorController', [
function() {
var vm = this;
vm.hue = '194.3';
vm.saturation = '100';
vm.lightness = '50';
vm.newHue = function() {
if (vm.hue) {
less.modifyVars({
hue: vm.hue
});
}
};
vm.newSaturation = function() {
if (vm.saturation) {
less.modifyVars({
saturation: vm.saturation
});
}
};
vm.newLightness = function() {
if (vm.lightness) {
less.modifyVars({
lightness: vm.lightness
});
}
};
}
]);
**index:**
<ul>
<li class="bgc-color-base"></li>
</ul>
<form data-ng-submit="color.newHue()" data-ng-controller="ColorController as color">
<label for="hue">Hue:</label>
<input type="text" id="hue" data-ng-model="color.hue" />
<input type="submit" value="Submit" />
</form>
<form data-ng-submit="color.newSaturation()" data-ng-controller="ColorController as color">
<label for="saturation">Saturation:</label>
<input type="text" id="saturation" data-ng-model="color.saturation" />
<input type="submit" value="Submit" />
</form>
<form data-ng-submit="color.newLightness()" data-ng-controller="ColorController as color">
<label for="lightness">Lightness:</label>
<input type="text" id="lightness" data-ng-model="color.lightness" />
<input type="submit" value="Submit" />
</form>
**less:**
ul {
list-style: none;
padding: 0;
margin-bottom: 20px;
li {
height: 100px;
&.bgc-color-base {
.background-base;
}
}
}
//== color variables
#hue: 194.3; // enter optional hue variable or custom hue range 0-330
#saturation: 100; // saturation range 0-100
#lightness: 50; // lightness range 0-100 (0 = black, 100 = white)
#alpha: 1;
//== base color function
#color-base: hsla(#hue, (#saturation/100), (#lightness/100), #alpha);
//== base color mixins
.background-base(#hue: #hue, #saturation: #saturation, #lightness: #lightness, #alpha: #alpha) {
background: #color-base;
}
You should have common controller for all three inputs otherwise the scope value change in one controller will not be available for the other controller
OR
If you want stay with separate controller then you need to create service that will have value of all variable is stored in it. That will share those values across.
Create a single method for updates less variable that will do the trick for you.
Markup
<body data-ng-app="colorChanger" data-ng-controller="ColorController as color">
<ul>
<li class="bgc-color-base"></li>
</ul>
<form data-ng-submit="color.updateColor()" >
<label for="hue">Hue:</label>
<input type="text" id="hue" data-ng-model="color.hue" />
<input type="submit" value="Submit" />
</form>
<form data-ng-submit="color.updateColor()"">
<label for="saturation">Saturation:</label>
<input type="text" id="saturation" data-ng-model="color.saturation" />
<input type="submit" value="Submit" />
</form>
<form data-ng-submit="color.updateColor()">
<label for="lightness">Lightness:</label>
<input type="text" id="lightness" data-ng-model="color.lightness" />
<input type="submit" value="Submit" />
</form>
</body>
Code
vm.updateColor = function() {
less.modifyVars({
hue: vm.hue || 194.3,
saturation: vm.saturation || 100,
lightness: vm.lightness || 50
});
};
And on html instead of calling three method on ng-submit call only one method vm.updateColor that will do less.modifyVars with all three variables.
Demo Plunkr

Keep dropdown visible while input boxes are focused

My navbar has dropdown "fieldsets" for login and search like this:
<div class="nav-button" id="nav-box">
<a class="inside-link">
<span id="inside-text">Sign in</span>
</a>
<fieldset id="menu-box" class="menu-box">
<form method="post" id="forms" class="forms" action="checklogin.php">
<label for="username">Username or email</label>
<input type="text" id="username" name="username" value="" title="username" tabindex="4">
<label for="password">Password</label>
<input type="password" id="password" name="password" value="" title="password" tabindex="5">
<input type="submit" id="small-btn" value="Sign in" tabindex="6">
<input type="checkbox" id="remember" name="remember_me" value="1" tabindex="7">
<label for="remember">Remember me</label>
<br />
Forgot your password?
<a id='forgot_username_link' title="If you remember your password, try logging in with your email" href="#">Forgot your username?</a>
</form>
</fieldset>
</div>
I have a fiddle here: http://jsfiddle.net/WBrns/5/
While input boxes like "search" "username" and "password" are focused, I'd like the associated dropdown to not disappear so users don't have to keep their mouse within the dropdown while typing.
Line 288 in the CSS was our first attempt which obviously doesn't work. My site already includes jQuery so any js/jquery solution is acceptable (since I think it's not possible with pure css)
Thanks!
On your hover style, make sure the attributes have the !important command and then use the code below while remembering to substitute the id's and classes to what you need:
$("input").focus(function () { that=this;
$(this).parent(".drop").css("display", "block");
$(this).blur(function() {
$(that).parent(".drop").css("display", "none");
});
})
You can take a look at an example here: http://jsfiddle.net/WBrns/12/
If a user begins to type, the drop down should not disappear even if they move their mouse away. However, if they click outside of the drop down, it will be hidden.
To improve upon Shaz's answer, you can name the blur event to prevent multiple blur events from being attached to the same input. I also recommend using a class name and CSS to show and hide the drop down so that you can take advantage of CSS transitions.
JS
$('input').focus(function () {
var $this = $(this);
var $drop = $this.parents('.drop');
$drop.addClass('open');
$this.bind('blur.closeDrop', function () {
$drop.removeClass('open');
$this.unbind('blur.closeDrop');
});
});
CSS
.drop {
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}
.drop.open {
opacity: 1;
pointer-events: auto;
}

Resources