Created
March 8, 2017 20:31
-
-
Save nickclyde/d79b4ff032af7070ea0d6f5e9d609030 to your computer and use it in GitHub Desktop.
Semantic UI File Upload Button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.field | |
.ui.button.fake-file-field | |
%i.upload.icon | |
%span.button-text Choose file | |
.hidden-file-field | |
= f.file_field :file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Turn file input into a button | |
$('.hidden-file-field').hide(); | |
$('.fake-file-field').click(function(e) { | |
$("input[type='file']").click(); | |
}); | |
$('.hidden-file-field').change(function() { | |
$('.button-text').text( | |
$('input[type=file]').val().split('\\').pop() | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment