Labeling file upload button - html

How can I internationalize the button text of the file picker? For example, what this code presents to the user:
<input type="file" .../>

It is normally provided by the browser and hard to change, so the only way around it will be a CSS/JavaScript hack,
See the following links for some approaches:
http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom
http://www.quirksmode.org/dom/inputfile.html
http://www.dreamincode.net/forums/showtopic15621.htm

Pure CSS solution:
.inputfile {
/* visibility: hidden etc. wont work */
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.inputfile:focus + label {
/* keyboard navigation */
outline: 1px dotted #000;
outline: -webkit-focus-ring-color auto 5px;
}
.inputfile + label * {
pointer-events: none;
}
<input type="file" name="file" id="file" class="inputfile">
<label for="file">Choose a file (Click me)</label>
source: http://tympanus.net/codrops

Take a step back! Firstly, you're assuming the user is using a foreign locale on their device, which is not a sound assumption for justifying taking over the button text of the file picker, and making it say what you want it to.
It is reasonable that you want to control every item of language visible on your page. The content of the File Upload control is not part of the HTML though. There is more content behind this control, for example, in WebKit, it also says "No file chosen" next to the button.
There are very hacky workarounds that attempt this (e.g. like those mentioned in #ChristopheD's answer), but none of them truly succeed:
To a screen reader, the file control will still say "Browse..." or "Choose File", and a custom file upload will not be announced as a file upload control, but just a button or a text input.
Many of them fail to display the chosen file, or to show that the user has no longer chosen a file
Many of them look nothing like the native control, so might look strange on non-standard devices.
Keyboard support is typically poor.
An author-created UI component can never be as fully functional as its native equivalent (and the closer you get it to behave to suppose IE10 on Windows 7, the more it will deviate from other Browser and Operating System combinations).
Modern browsers support drag & drop into the native file upload control.
Some techniques may trigger heuristics in security software as a potential ‘click-jacking’ attempt to trick the user into uploading file.
Deviating from the native controls is always a risky thing, there is a whole host of different devices your users could be using, and whatever workaround you choose, you will not have tested it in every one of those devices.
However, there is an even bigger reason why all attempts fail from a User Experience perspective: there is even more non-localized content behind this control, the file selection dialog itself. Once the user is subject to traversing their file system or what not to select a file to upload, they will be subjected to the host Operating System locale.
Are you sure you're doing your user any justice by deviating from the native control, just to localize the text, when as soon as they click it, they're just going to get the Operating System locale anyway?
The best you can do for your users is to ensure you have adequate localised guidance surrounding your file input control. (e.g. Form field label, hint text, tooltip text).
Sorry. :-(
--
This answer is for those looking for any justification not to localise the file upload control.

You get your browser's language for your button. There's no way to change it programmatically.

much easier use it
<input type="button" id="loadFileXml" value="Custom Button Name"onclick="document.getElementById('file').click();" />
<input type="file" style="display:none;" id="file" name="file"/>

I could achieve a button using jQueryMobile with following code:
<label for="ppt" data-role="button" data-inline="true" data-mini="true" data-corners="false">Upload</label>
<input id="ppt" type="file" name="ppt" multiple data-role="button" data-inline="true" data-mini="true" data-corners="false" style="opacity: 0;"/>
Above code creates a "Upload" button (custom text). On click of upload button, file browse is launched. Tested with Chrome 25 & IE9.

To make a custom "browse button" solution simply try making a hidden browse button, a custom button or element and some Jquery. This way I'm not modifying the actual "browse button" which is dependent on each browser/version. Here's an example.
HTML:
<div id="import" type="file">My Custom Button</div>
<input id="browser" class="hideMe" type="file"></input>
CSS:
#import {
margin: 0em 0em 0em .2em;
content: 'Import Settings';
display: inline-block;
border: 1px solid;
border-color: #ddd #bbb #999;
border-radius: 3px;
padding: 5px 8px;
outline: none;
white-space: nowrap;
-webkit-user-select: none;
cursor: pointer;
font-weight: 700;
font: bold 12px/1.2 Arial,sans-serif !important;
/* fallback */
background-color: #f9f9f9;
/* Safari 4-5, Chrome 1-9 */
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#C2C1C1), to(#2F2727));
}
.hideMe{
display: none;
}
JS:
$("#import").click(function() {
$("#browser").trigger("click");
$('#browser').change(function() {
alert($("#browser").val());
});
});

Actually, it is possible to customize the Upload File button with its pseudo selector: ::file-selector-button.
Check this for more info: MDN ::file-selector-button - CSS

Related

Email HTML template <form> not working

I'm sending HTML mail built with Freemarker from my webapp. In the email, there is a button inside a <form> tag as follows (fake URL):
<form action="http://192.168.123.456:23080/path/">
<button style="border: 0; background-color: #003399; padding: 20px 40px; font-size: 18px; color: #FFFFFF; font-style: initial; cursor: pointer">ACCESS</button>
</form>
The form works on Google Chrome, even GMail on Chrome as well, but it does not work inside Outlook or from IExplorer (tested in IE11). When you click on the button nothing happens.
Are there any security constraints about it?
Plenty of email clients do not support forms in HTML formatted email.
It isn't clear if the restriction is for security reasons or other reasons (or if it varies from client to client).
Either way, the restriction does exist. You should generally just include a link in the email that points to a regular HTTPS hosted page containing a form.

IE8 text-indent and placeholder issue

I have two problems here:
1) Place holder
2) Cursor text indent
First, I googled a bit, and know that the placeholder is a HTML5 feature and isn't support in IE8. Is there an alternate solution?
Second, in IE8, the cursor doesn't start with text indent.
HTML:
<input autofocus="autofocus" id="home_email_input" name="username" placeholder="E-mail" type="text">
<input id="home_pw_input" name="password" placeholder="PW" type="password">
CSS:
#home_email_input {
margin-left: 22px;
margin-bottom: 10px;
width: 183px;
background: url(/images/envelope.gif) no-repeat scroll 4px 3px;
text-indent: 30px;
}
#home_pw_input {
margin-left: 22px;
margin-bottom: 10px;
width: 183px;
background: url(/images/lock.gif) no-repeat 5px -0.5px;
text-indent: 30px;
}
Add line-height to get the indent work for IE
Here you go:
http://jsfiddle.net/Cernx/12/
For the placeholder, you must use javascript. There is not other alternative in HTML.
Use the webshims library to shim the placeholders in
For the text indent, just add extra left padding to the input box for IE
The alternative solution is to have labels for the input fields, instead of using placeholder as an unreliable surrogate for a label. The placeholder is supposed to help the user e.g. with a description of the expected input format, not to do the job of a label. Example:
<label for=email>E-mail:</label> <input type=email id=email name=email>
The HTML5 CR says about the placeholder attribute: “The placeholder attribute should not be used as a replacement for a label. [...] Use of the placeholder attribute as a replacement for a label can reduce the accessibility and usability of the control for a range of users including older users and users with cognitive, mobility, fine motor skill or vision impairments. While the hint given by the control's label is shown at all times, the short hint given in the placeholder attribute is only shown before the user enters a value. Furthermore, placeholder text may be mistaken for a pre-filled value, and as commonly implemented the default color of the placeholder text provides insufficient contrast and the lack of a separate visible label reduces the size of the hit region available for setting focus on the control.”

How to change the behavior and style of an html file field?

I'd like to create a file upload field that displays an input type=text (displaying the filename), with the upload button replaced with a custom image.
Something like this:
A simple solution without any hacks would be appreciated.
You won't find any solutions that aren't hacks due to how browsers handle the file upload field. Due to security concerns they restrict the amount of styling you can do to them to prevent a malicious website from making them look like something they are not. How limited you are varies from browser to browser but without using JavaScript and hacky tricks you will not be able to style a file upload field to your liking through straight HTML/CSS.
<INPUT type="image" class="myButton" value="">
.myButton {
background:url(YOUR IMAGE) no-repeat;
cursor:pointer;
width: 200px;
height: 100px;
border: none;
}
using buttons
<button type="submit" style="border: 0; background: transparent">
<img src="/images/Btn.PNG" width="90" heght="50" alt="submit" />
</button>
If you are using jQuery, have a look at this plugin - https://github.com/ajaxray/bootstrap-file-field
This tiny plugin will display the file input field as a bootstrap button (with configurable classes), similar in all browser and will show selected file names (or selection errors) beautifully.
Additionally you can set various restrictions using simple data-attributes or JS settings. e,g, data-file-types="image/jpeg,image/png" will restrict selecting file types except jpg and png images.

please advice a better link button and return false solution

html has link element
as well as button element
<button></button>
in fact their responsibility are different but... sometimes design want them look the same.
I don't any clue to style them look exactly the same, beside reset display, margin, padding, border, background, font etc... they won't look the same at the end and sometimes they screw up each other default positioning attribute.
so my initial solution as below:
example of a link
designer want a link look like a button. I wrap a button in a link!
<button class="coolbutton">look cool</button>
I like this solution, especially i think a button are a lot easier to style.
then the a tag will response to the click and link
now, example of a form :
a button for submit the form and a links beside the button. they need to look the same.
and the link button shouldn't submit the form.
but it is inside the form...
<button class="coolbutton onclickreturnfalse">I just want to link it</button>
<button> Submit </button>
the class .onclickreturnfalse are bind to javascript click event to return false anyway. so it won't submit the form... but the problem is.. it return false to the link also.. so the link won't work...
sorry for my poor description and title. I need some opinion now. how a web designer solve these problems?
#
so i put my CSS here
#
button,a.bt1,a.bt2,a.bt3{
border: 1px solid rgba(152, 152, 152, 0.1);border-radius: 2px;color: #666666;cursor: pointer;
font-size: 8pt;font-weight: bold;min-width: 54px;padding: 4px 8px;text-align: center;
}
button,button.bt1,a.bt1 { background-color: #F5F5F5; }
button.bt2,a.bt2 { background-color: #F5F5F5; color:#BF0000; }
button.bt3,a.bt3 { background-color: #BF0000; color:#EFEFEF; }
button:hover,a.bt1:hover,a.bt2:hover,a.bt3:hover{
border: 1px solid rgba(208, 0, 0, 0.1); text-decoration:none;
}
seriously... they look a little bit different :(
You should either use a button or an anchor, but I don't see why would you use a button inside a link. You can style the anchor to look as a button or simply use a button and handle the click event.
For example, clicking on this link will not cause a postback (with JS enabled in the browser): <a href="#" class="coolbutton" onclick="alert('test'); return false;" />

Image on Browse and upload file button

I want to have image button for "browse" and "upload"
I have textbox using the following code:
CSS
.uploadpathdiv
{
margin:0;
height:44px;
width:464px;
background:url('images/img-upload.png') no-repeat bottom;
}
.uploadpath
{
background:none;
border:none;
width:400px;
height:40px;
margin:0;
padding: 2px 7px 0px 7px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
}
HTML
<div class="uploadpathdiv">
<input class="uploadpath" name="path" type="text" />
</div>
<img src="/themes/scaccarium/images/button-upload.png" />
<img src="/themes/scaccarium/images/button-browse.png" />
The image code is for both "browse" and "upload" button.
Please help me to correct the above code so that when i press the browse button i get "file selection option" as you see when you use <input type = "file" name="browse">. Secondly, the path of the file must be shown in the textbox above.
Thirdly when i press the upload button the file should be uploaded
If you label an image with the label tag, you can click on the image and it will select the browse button.
<div id="fileInput">
<label for="FileID"><img src="ImageURL"></label>
<input type="file" id="FileID"/>
</div>
It is not possible to target the "browse..." button of file upload controls via CSS.
A HTML-based workaround can be found here: Styling an input type="file"
not sure whether it can do exactly what you need, but I think that's the closest you can get.
If you want full control over the control (no pun intended) you would have to use a Flash-based uploader like SWFUpload. Note that those uploaders work a bit differently from a normal file upload control, so you may need to change your workflow to get it to work, and decide whether it's worth the effort.
Most of the CSS properties we usually use to style form controls don’t have any effect on the upload control, there are ways to style it, a good example is Here
This technique basically sets the opacity of the control to 0 and placed another "styled" button underneath it. thus when clicking on the style button you are actually clicking the upload control.
I have spent many hours battling with custom file upload controls for clients and have found by far the best approach is making use of Valums jquery file uploader everything is already built and you can customize as much as you want, also has drag and drop functionality.