Semantic-UI icon indicating copy to clipboard operation
Semantic-UI copied to clipboard

[Form] Add File Input Styles

Open alihalabyah opened this issue 10 years ago • 117 comments

It would be nice if the file input styled and has some effects.

alihalabyah avatar Dec 04 '13 20:12 alihalabyah

Usually file inputs are styled by styling a <label>, and hiding the <input>. I recommend something like this:

<div>
    <label for="file" class="ui icon button">
        <i class="file icon"></i>
        Open File</label>
    <input type="file" id="file" style="display:none">
</div>

brigand avatar Dec 04 '13 23:12 brigand

Agreed about input type file, have some idea for this and drop zone for file drag&drop

jlukic avatar Dec 05 '13 04:12 jlukic

:+1:

patie avatar Jan 11 '14 14:01 patie

So, how's it going with this? Should be easy to implement as module, right?

Anachron avatar Feb 02 '14 18:02 Anachron

Thank you, brigand.

I write something like this(http://jsfiddle.net/nickevin/a4sD4/), YES, i copy your code.

2014-02-27_110239

<div class="field">
    <div class="ui action input">
        <input type="text" id="_attachmentName">
        <label for="attachmentName" class="ui icon button btn-file">
             <i class="attachment basic icon"></i>
             <input type="file" id="attachmentName" name="attachmentName" style="display: none">
        </label>
    </div>
</div>        
var fileExtentionRange = '.zip .rar .tar .pdf .doc .docx .xls .xlsx .ppt .pptx';
var MAX_SIZE = 30; // MB

$(document).on('change', '.btn-file :file', function() {
    var input = $(this);

    if (navigator.appVersion.indexOf("MSIE") != -1) { // IE
        var label = input.val();

        input.trigger('fileselect', [ 1, label, 0 ]);
    } else {
        var label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
        var numFiles = input.get(0).files ? input.get(0).files.length : 1;
        var size = input.get(0).files[0].size;

        input.trigger('fileselect', [ numFiles, label, size ]);
    }
});

$('.btn-file :file').on('fileselect', function(event, numFiles, label, size) {
    $('#attachmentName').attr('name', 'attachmentName'); // allow upload.

    var postfix = label.substr(label.lastIndexOf('.'));
    if (fileExtentionRange.indexOf(postfix.toLowerCase()) > -1) {
        if (size > 1024 * 1024 * MAX_SIZE ) {
            alert('max size:<strong>' + MAX_SIZE + '</strong> MB.');

            $('#attachmentName').removeAttr('name'); // cancel upload file.
        } else {
            $('#_attachmentName').val(label);
        }
    } else {
        alert('file type:<br/> <strong>' + fileExtentionRange + '</strong>');

        $('#attachmentName').removeAttr('name'); // cancel upload file.
    }
});

nickevin avatar Feb 27 '14 03:02 nickevin

I think you may want to make the first input disabled. Normally you don't want people do edit the file name when they are uploading.

FrancisMengx avatar Aug 20 '14 01:08 FrancisMengx

Any expected date for this feature. We are using at many places and only those are looking different.

ranga-nathan avatar Oct 31 '14 10:10 ranga-nathan

Maybe take a look at this one, it's pretty good: http://plugins.krajee.com/file-input/demo

Anachron avatar Oct 31 '14 12:10 Anachron

The issue is still opened, any ideas about adding this feature?

Landish avatar Dec 13 '14 21:12 Landish

mikemix avatar Jan 14 '15 13:01 mikemix

The Bootstrap demo page is very nice. This would indeed be a nice addition to this library.

tiborsaas avatar Jan 26 '15 13:01 tiborsaas

+1

cspeer avatar Jan 27 '15 16:01 cspeer

+1

sos0 avatar Feb 06 '15 01:02 sos0

+1

nyaaao avatar Feb 11 '15 10:02 nyaaao

+1

francodgstn avatar Feb 18 '15 02:02 francodgstn

There’s a Meteor package for file uploads that claims its file upload control is styled for Semantic UI: https://github.com/tomitrescak/meteor-uploads

Perhaps the control from this package can be decoupled from Meteor and adapted for front-end use anywhere?

GeoffreyBooth avatar Feb 19 '15 00:02 GeoffreyBooth

+1

dmitrijs-balcers avatar Mar 05 '15 18:03 dmitrijs-balcers

+1 waiting for this feature, i need so much.

BenevidesLecontes avatar Apr 11 '15 09:04 BenevidesLecontes

+1

NexPB avatar Apr 12 '15 16:04 NexPB

+1

hmaesta avatar Apr 29 '15 20:04 hmaesta

+1

metasyn avatar Apr 30 '15 19:04 metasyn

+1

piya23300 avatar May 17 '15 17:05 piya23300

+1

listepo avatar Jun 01 '15 08:06 listepo

+1

rumen-yankov avatar Jun 04 '15 10:06 rumen-yankov

+1

Ethaan avatar Jun 12 '15 07:06 Ethaan

+1

kodamirmo avatar Jun 14 '15 05:06 kodamirmo

+1

opvini avatar Jun 18 '15 17:06 opvini

I guess this is pretty low hanging fruit.

jlukic avatar Jun 18 '15 21:06 jlukic

Good news!

dmitrijs-balcers avatar Jun 19 '15 14:06 dmitrijs-balcers

What did you all do in the mean time ?

metasyn avatar Jun 24 '15 04:06 metasyn