Image for form label - forms

I am quite interested in exploring accessibility in forms and accessibility in general.
Is it against the rules to use an image as a label if the image also has an alt tag representing the the label? Would this be ok? If not what is the best approach? I have a small form for clients to enter their links to the social sites they use and would like to use the logo of the social site rather than text (label).
Thanks,
Jack

I think it would be better to use CSS class:
<div class="social">
<label for="social1" class="s1">Social 1</label>
<input type="text id="social1" name="social1" />
<label for="social2" class="s2">Social 2</label>
<input type="text id="social2" name="social2" />
</div>
So you could apply background like this:
.social {
display: block;
width: 50px;
height: 50px;
background-repeat: no-repeat;
}
.social .s1{
background-image: url("social1.gif");
}
.social .s2{
background-image: url("social2.gif");
}
I would not remove text from the labels. So it would be possible for users to select that text but still look like an image (with appropriate background).
But if you really want to stick with images only then you can use this approach:
<div class="social">
<label for="social1" class="s1">
<img alt="Social 1" src="img/social1.gif" />
</label>
<input type="text id="social1" name="social1" />
<label for="social2" class="s2">
<img alt="Social 2" src="img/social2.gif" />
</label>
<input type="text id="social2" name="social2" />
</div>
and answering your question, I think it is ok to have images with alt text.

Disclaimer: I'm not a usability expert
I think it would depend on a few factors.
Are the links all to sites that have well known brands/logos? Will people understand that it's not some random art?
Is there some context that indicated that it is clickable? For instance, is this in a table where one of the table headers states "Link"? Does it highlight when you mouse over it?
Is there a reason why typical text links would look particularly ugly or nondistinctive?
Are there sites with similar functionality that do the same thing?
I hope this helps in some fashion!

Related

Spacing between the glyphicon and text?

I am trying to add a glyph icon as part of an email address link. The icon shows but there is no spacing between the icon and the email address text (I want the hyperlink to include both the icon and the text... including the space). What's the best way to accomplish this?
<a href="mailto:someone#somewheredotcom" title="Some Email">
<span class="glyphicon glyphicon-envelope">someone#somewheredotcom</span>
</a>
You can try to do this:
.glyphicon-envelope:before {
margin-right: 5px;
}
Be aware that your custom css file should be included after bootstrap.css
If you using only glyphicon just add one space after </span> tag like below
<span class="glyphicon glyphicon-user"></span> Individual
If you using glyphicon along with font awesome library reference just add fa-fw at the end of class.
<a href="mailto:someone#somewheredotcom" title="Some Email">
<span class="glyphicon glyphicon-envelope fa-fw">someone#somewheredotcom</span>
</a>
From http://getbootstrap.com/components/, see this note
Be sure to leave a space between the icon and text for proper padding.
So, you can modify the CSS if desired, for example using Bogdan's idea, or just by adding between the icon and your text:
<a href="mailto:someone#somewheredotcom" title="Some Email">
<span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> someone#somewheredotcom
</a>
According to Bootstrap:
Icon classes should only be used on elements that contain no text content and >have no child elements.
You should put the email address outside of span:
<span class="glyphicon glyphicon-envelope fa-fw"></span>someone#somewheredotcom

Change label color in form with error

I'm buzy with a validation plug-in. When someone clicks on the submitbutton and the required fields are not filled, the border-color of the concerning fields changes to red. My problem however is that I also want the color of the text next to it to change. This is my structure:
<div class="row">
<label for="name">Name*</label>
<input type="text" id="name" name="name">
</div>
.form.a input.error {border:2px solid #eb053b;}
How can I now select the label-element to change the text color? It's not possible with CSS, because you can't select a parent-element, but I don't know how to do it with jQuery.
You can trigger this event on clicking the submit button
if(jQuery('.form.a input').css('border')==2px solid #eb053b){
jQuery(this).siblings('label').css('color','#eb053b');
}
As I mentioned in the comments, the jquery validator adds a label after the input box by default with a class 'error'. Though I haven't found the hack for stopping the validator from doing this yet, here is something that I practice in my forms.
HTML:
<div class="row">
<input type="text" id="name" placeholder="Name (required)" name="name">
</div>
CSS:
.form.a input.error {border:2px solid #eb053b;}
label.error { color: #ebo53b;}
FIDDLE
This would produce a meaningful error message in a label after the input box in red color.
The error messages can be customized using the rules option of jquery validator, the placement of label (before or after) is changed by the errorPlacement option.
I'll update my answer if and when I find the exact solution to your problem.

Checkboxes not "checking" - trying to read someone else's code

I am trying to read someone else's code (they're on vacation), and they're using HTML 5 which I am less familiar with.
For some reason, when I click the checkboxes, they aren't selecting.
Here's the code:
<fieldset>
<legend>I would like a quote on the following products:</legend>
<div class="divider">
<h3 style="cursor: pointer;">
<input type="checkbox" value="Selective Pallet Rack – Roll Formed" name="Quote_on_Products[]">
Roll Formed Selective Pallet
</h3>
<h3 style="cursor: pointer;">
<input type="checkbox" value="Selective pallet Rack – Structural" name="Quote_on_Products[]">
Structural Selective Pallet
</h3>
<h3 style="cursor: pointer;">
<input type="checkbox" value="Drive In / Drive Thru Rack" name="Quote_on_Products[]">
Drive In / Drive Thru Rack
</h3>
<h3 style="cursor: pointer;">Other</h3>
<textarea name="Other_Products"></textarea>
</div>
<div class="divider">
<h3 style="cursor: pointer;">
<input type="checkbox" value="Push Back Rack" name="Quote_on_Products[]">
Push Back Rack
</h3>
<h3 style="cursor: pointer;">
<input type="checkbox" value="Pallet Flow Rack" name="Quote_on_Products[]">
Pallet Flow Rack
</h3>
<h3 style="cursor: pointer;">
<input type="checkbox" value="Cantilever Rack" name="Quote_on_Products[]">
Cantilever Rack
</h3>
<h3 style="cursor: pointer;">
<input type="checkbox" value="Safety Products" name="Quote_on_Products[]">
Safety Products
</h3>
</div>
</fieldset>
Could it be the h3 tag? The values containing odd characters? I'm at a loss as to why it wouldn't allow me to click a checkbox.
It's hard to debug code you didn't write and have never seen before. You might want to check any relevant javascript files that could be preventing the checkboxes from being checked. Click event handlers can be added dynamically on page load from a js file, and those handlers could be doing almost anything, including messing with your checkboxes.
Nothing wrong with the Html. I have created JSFiddle with your Html and I am able to check checkboxes. Here is the JsFiddle http://jsfiddle.net/zDwkH/
As ean5533 rightly pointed out, check if there is any javascript that is preventing these checkboxes from being checked.
If button events are not working, find out what's happening. Use either firebug, or IE (believe it or not) to find out what the current onclick event is. If it the code has return false at the end of it, this is why it is apparently 'doing nothing'.
But, also consider that it could be a rendering issue. For instance if there's a layer sitting above it with higher z-index that you can't see, the buttons may not be firing their onclick functions!
I just had this problem as well and noticed this rule in the CSS
input { -webkit-appearance:none; }
Its purpose is to prevent iOS from applying its own styling to buttons. It also prevented the tick appearing so I moved the rule into input[type=submit], button. Problem solved.

HTML <label> command doesn't work in Iphone browser

In a html page I am making, I tried to make div's clickable using html and css. This has worked perfectly in some major browsers I have tested it in (Chrome, Firefox, Opera, Safari), as well as an HTC phone, but when I tried to test it on Iphone I noticed it just didn't work. The checkboxes themselves weren't even selectable.
This is my (working apart from on Iphone) code:
HTML:
<div class="" style="height: 30px;">
<div style="display: table; width: 100%;">
<div style="display: table-row; width: 100%;">
<div style="display: table-cell;">
<label for="3171">Text....</label>
</div>
<div style="display: table-cell; text-align: right;">
<input type="checkbox" id="3171" name="3171">
</div>
</div>
</div>
<label for="3171">
<span class="blocklink">Invisible text</span>
</label>
</div>
CSS:
.blocklink {
display: block;
height: 100%;
left: 0;
overflow: hidden;
position: absolute;
text-indent: -999em;
top: 0;
width: 100%;
}
So as you can see the technique I'm using is basicly just having a <label> spread all over the parent div so anywhere you click, it will tick/untick the linked checkbox.
Unfortunately, this doesn't work on IPhone. Would it be possible to somehow keep using this technique but also provide IPhone support? (Preferrably without javascript, because I'm really going out of my way to only use HTML & CSS)
Thanks in advance,
Arne
Adding an empty onclick="" to the label makes the element clickable again on IOS4. It seems that by default the action is blocked or overtaken by the press and hold copy and paste text mechanics.
<label for="elementid" onclick="">Label</label>
The problem seems to persists in iOS9 if any html elements are contained inside a label. At least happens with span elements inside it. 'pointer-events: none' fixes it.
<label for="target">
<span>Some text</span>
</label>
The code above would not be trigger a change of the target input, when the user taps 'Some Text', unless you add the following css:
label span {
pointer-events: none;
}
I solved it by placing an empty onclick="" on a parent element:
<form onclick="">
<input type="radio" name="option1" value="1">
<label for="option1">Option 1</label>
<input type="radio" name="option2" value="2">
<label for="option2">Option 2</label>
<input type="radio" name="option3" value="3" checked="checked">
<label for="option3">Option 3</label>
</form>
For some obscure reason, using CSS, if you apply:
label { cursor: pointer; }
Is going to work both on iPhone and iPad.
Another solution — albeit more hacky, but bulletproof — would be to absolutely position the checkbox over the label, z-index it, increase the width/height to encompass the underlying label and then 0 the opacity. This, of course would be tedious if there are multiple labels on the page... You naturally would also only implement the absolute positioning for that media size; no need to hack the whole app environment.
I ran into a somewhat unique situation. We were already using pointer-events: none on all spans in labels. However, we then needed to add in a <a> as clickable within one of those labels.
<label>
<span>Label text here. With a link text here.</span>
</label>
So, we explicitly set pointer-events: all on those <a>.
label > span { pointer-events: none; }
label > span > a { pointer-events: all; }
This is working in latest Chrome, Firefox, IE 11, and iOS 9 Safari.
If you change DOM on event handler (example in onMouseEnter) this cause skip all next handlers include onClick.
SetTimeout don't fix this.
Example:
1. in onMouseEnter use setTimeout with function injected new div in DOM
2. any onClick handler don't called.
Solution: avoid change DOM in events handler.
Remark: it problem found for label tag, but still persist for span inside label. May be this problem present on any type tags.
This behavuor found only for mobile iOS. In desktop Safari and in Mac OS Safari - all ok.
I narrowed down my problem to use of the Fastclick library; when I removed it from my codebase my issues went away, which indicates to me there isn't a native iOS/FF problem as suggested by other answers here.
Without knowing the libraries other folks are using, but knowing that Fastclick is exceptionally common, can I suggest that the root cause of this bug is in fact a library issue - not one which has managed to persist through years of Apple releases! It seems more likely. Maybe the others here can shed some light on whether they are using Fastclick?
More info
Some browsers prevent file inputs from being triggered by client code as a security measure. Try triggering a click event from the console with document.querySelector('input[type=file]').click() and it'll work, do the same from your code and it will mysteriously fail.
I imagine the reason this bug exists is because an ontouchstart handler is being applied to the <label /> by Fastclick. When it is triggered on a touch device, the library will proxy that event to the onclick handler, or in this case the native <label /> functionality. Unfortunately, this means that client code is triggering the file input opening, and it's being blocked by the browser.

fb:visible-to-connection Not Working!

I don't usually deal in exclamation points, but I have hours before this goes live. I have the following page full of FBML for a Facebook tab on a product page:
<fb:fbml version="1.1">
<div id="container" style="width: 520px;">
<fb:visible-to-connection>
<div>
Yay!
<a href="{link}" style="border: 0; display:inline-block;">
<img src="{image link}" style="border: none;" />
</a>
</div>
<fb:else>
<div>
<img src="{image link}" style="border: none;" />
</div>
</fb:else>
</fb:visible-to-connection>
<div class="{a css class I have to censor}">
<img src="{image link}" />
<p class="nopurchase" style="font-family: 'Trebuchet MS Gothic', Arial; font-size: 10px;">
some text.
Click for something.</p>
</div>
</div>
</fb:fbml>
Basically it's a fan gate. To get past it the user has to like the page it resides on. It parses and renders, but for whatever reason both conditions (the div for fans, and the one for non-fans) are drawn. I have no idea why fb:visible-to-connection isn't doing this.
The answer is simple. If you are an admin of the application you are using, visible-to-connection will show you everything, regardless whether you're a fan or not. Normal users will see the expected functionality.
Yep, if you are an admin you get the trap all the time. If you go to the page with an account that is not an admin you can like the page and then see the content as expected. Thanks
Go to ACCOUNT on the top right of your screen
Click USE FACEBOOK AS PAGE
Select another page, then check your functionality - this should work