Created
November 6, 2018 02:40
-
-
Save harrisonmalone/bade9ce79c61a73caabd258dcd2b7be9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<div class="container"> | |
<%= form_for @album, url: albums_path, html: {class: "nifty-form"} do |f| %> | |
<%= f.label :name %> | |
<%= f.text_field :name %> | |
<label for="images" class="custom-file-upload">Upload Images</label> | |
<%= f.file_field :images, id: "images", multiple: true, onchange: "myFunction()" %> | |
<%= f.submit "Create" %> | |
<% end %> | |
<p class="sub-head">Images selected</p> | |
<p id="demo"></p> | |
<script> | |
function myFunction(){ | |
var x = document.getElementById("images"); | |
var txt = ""; | |
if ('files' in x) { | |
if (x.files.length > 0) { | |
for (var i = 0; i < x.files.length; i++) { | |
txt += "<div class='upload'>" + "Image" + " " + (i+1) + "</div>"; | |
var file = x.files[i]; | |
if ('name' in file) { | |
txt += "<div class='upload-name'>" + file.name + "</div>"; | |
} | |
} | |
} | |
} | |
document.getElementById("demo").innerHTML = txt; | |
} | |
</script> | |
</div> |
This file contains hidden or 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
.container { | |
max-width: 600px; | |
margin: 0 auto; | |
} | |
.nifty-form label { | |
font-size: 15px; | |
font-family: sans-serif; | |
} | |
.nifty-form input[type=text] { | |
width: 100%; | |
padding: 12px 20px; | |
margin: 8px 0; | |
display: inline-block; | |
border: 1px solid #ccc; | |
border-radius: 4px; | |
box-sizing: border-box; | |
font-size: 16px; | |
} | |
.nifty-form input:focus { | |
border: 1px solid grey; | |
} | |
.nifty-form input[type=submit] { | |
width: 100%; | |
background-color: blueviolet; | |
color: white; | |
padding: 14px 20px; | |
margin: 8px 0; | |
border: none; | |
border-radius: 4px; | |
cursor: pointer; | |
font-size: 16px; | |
} | |
.custom-file-upload { | |
background-color: blueviolet; | |
color: white; | |
padding: 14px 20px; | |
margin: 8px 0; | |
border: none; | |
border-radius: 4px; | |
cursor: pointer; | |
font-size: 16px; | |
display: inline-block; | |
} | |
.nifty-form input[type="file"] { | |
display: none; | |
} | |
.sub-head { | |
font-size: 18px; | |
font-family: sans-serif; | |
} | |
.upload { | |
font-size: 15px; | |
font-family: sans-serif; | |
} | |
.upload-name { | |
font-size: 15px; | |
font-family: sans-serif; | |
margin: 5px 0px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment