Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Form] Add File Input Styles #403

Open
alihalabyah opened this issue Dec 4, 2013 · 117 comments
Open

[Form] Add File Input Styles #403

alihalabyah opened this issue Dec 4, 2013 · 117 comments
Milestone

Comments

@alihalabyah
Copy link

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

@brigand
Copy link
Contributor

brigand commented Dec 4, 2013

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>

@jlukic
Copy link
Member

jlukic commented Dec 5, 2013

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

@patie
Copy link

patie commented Jan 11, 2014

👍

@Anachron
Copy link

Anachron commented Feb 2, 2014

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

@nickevin
Copy link

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.
    }
});

@jlukic jlukic added this to the 1.x Changes milestone Mar 14, 2014
@jlukic jlukic changed the title [Input] Add styling for file inputs [Form] Add File Input Styles Jun 18, 2014
@FrancisMengx
Copy link

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.

@ranga-nathan
Copy link

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

@Anachron
Copy link

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

@liorocks
Copy link

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

@mikemix
Copy link

mikemix commented Jan 14, 2015

@tiborsaas
Copy link

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

@cspeer
Copy link

cspeer commented Jan 27, 2015

+1

3 similar comments
@sos0
Copy link

sos0 commented Feb 6, 2015

+1

@nyaaao
Copy link

nyaaao commented Feb 11, 2015

+1

@francodgstn
Copy link

+1

@GeoffreyBooth
Copy link

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?

@dmitrijs-balcers
Copy link

+1

@BenevidesLecontes
Copy link

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

@NexPB
Copy link

NexPB commented Apr 12, 2015

+1

2 similar comments
@hmaesta
Copy link

hmaesta commented Apr 29, 2015

+1

@metasyn
Copy link

metasyn commented Apr 30, 2015

+1

@jlukic jlukic modified the milestones: 2.0, 1.x Changes May 4, 2015
@piya23300
Copy link

+1

1 similar comment
@listepo
Copy link

listepo commented Jun 1, 2015

+1

@jlukic jlukic modified the milestones: 2.x Changes, 2.0 Jun 1, 2015
@fx
Copy link

fx commented Aug 16, 2017

@hmaesta no worries, nobody's demanding anything. Just poking a little fun at the age of this one and keeping it alive :)

@jafarpagerjaya
Copy link

jafarpagerjaya commented Sep 21, 2017

I hope these give you a little hint guys https://jsfiddle.net/09hp81dd/6/

@Anachron
Copy link

@jafarpagerjaya but that has nothing to do with File Input Styles? Doh.

@hmaesta
Copy link

hmaesta commented Sep 21, 2017

@Anachron Yes, it does. Mouseover image and click the button.

It is a good contribution, thank you @jafarpagerjaya.

@Anachron
Copy link

Oh wow, that's very hidden! Just a bit non-fitting to the rest of Semantic UI!

@agamm
Copy link

agamm commented Sep 21, 2017

Sorry if this is rude, but is this still headed to be added in the near future?

@GuacheSuede
Copy link

#6109

@jlukic jlukic modified the milestones: 2.2.15, 2.2.16 Jan 29, 2018
@laurentlahmy
Copy link

laurentlahmy commented Feb 10, 2018

For those using React:

Seems to be less of a headache (and no jQuery) this way:
https://stackoverflow.com/questions/37457128/react-open-file-browser-on-click-a-div

quoting:

Add the ref attribute to your input:

<input type="file" id="file" ref="fileUploader" style={{display: "none"}}/>
Change the handleClick function:
handleClick(e) {
    this.refs.fileUploader.click();
}

@austingayler
Copy link

austingayler commented Mar 8, 2018

I'm using react-semantic-ui, and I had to do this.upload.inputRef.click() (where upload is the ref)

@subramaniyanan176
Copy link

I am also looking for the same for using in angular..

@brunotourinho
Copy link

I have worked around this issue this way:

<div class="field six wide">
    <label>File</label>
    <div class="ui action input">
	<input type="text" readonly>
	<input type="file" name="File" style="display: none!important;" />
	<div class="ui icon button">
	    <i class="cloud upload alternate icon"></i>
	</div>
    </div>
</div>

then in JS

$('input:text, .ui.button', '.ui.action.input').on('click', function (e) {
    $('input:file', $(e.target).parents()).click();
});

$('input:file', '.ui.action.input').on('change', function (e) {
    var name = e.target.files[0].name;
    $('input:text', $(e.target).parent()).val(name);
});

@subramaniyanan176
Copy link

thanks a lot. let me try this

@jlukic jlukic modified the milestones: 2.3.1, 2.3.2, 2.3.3 Mar 19, 2018
@pptom
Copy link

pptom commented Apr 27, 2018

it's been 5 years...

@omairvaiyani
Copy link

😞

@michaelmarziani
Copy link

+1 Using Semantic UI with React and really enjoying it. File uploads are an important feature and would love to have these styled like the rest of Semantic UI.

@WilliamChou06
Copy link

+1 Semantic UI is a very beautiful framework and would definitely be even better having file uploads styled!

@rizqtino
Copy link

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.
    }
});

im sorry im still confused with this

@DennisLoska
Copy link

Well it's been 6 years^^

@omairvaiyani
Copy link

@DennisLoska This project is currently in hiatus with all development taking place over at Fomantic UI

@DennisLoska
Copy link

@omairvaiyani Thanks for the info. They don't have a file uploader component yet, but at least the last comment was like two weeks ago fomantic/Fomantic-UI#105

@kdssoftware
Copy link

It's now 2021, this issue was created on 2013...

@Anachron
Copy link

Anachron commented Jan 16, 2021

Then go & implement it yourself?
There is Fomatic UI, too, where you can help out.

@lubber-de

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests