Class: ImageFileInput
- Inherits:
-
SimpleForm::Inputs::Base
- Object
- SimpleForm::Inputs::Base
- ImageFileInput
- Defined in:
- app/inputs/image_file_input.rb
Overview
SimpleForm input wrapper: image file.
Instance Method Summary collapse
Instance Method Details
#input(wrapper_options = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/inputs/image_file_input.rb', line 4 def input( = nil) = (, ) # For simple form uploads, use a standard file input with preview container_id = "image-upload-#{SecureRandom.hex(8)}" # Standard file input (accept any file; preview only when renderable) file_input = @builder.file_field(attribute_name, .merge( id: container_id, class: 'form-control image-file-input', data: { preview_id: "#{container_id}-preview", max_size: [:max_file_size] || 10.megabytes } )) # Preview container preview_container = template.tag.div('', id: "#{container_id}-preview", class: 'image-preview-container mt-2', style: 'display: none;') # Wrapper container with Stimulus controller template.tag.div( file_input + preview_container, class: 'image-upload-wrapper', data: { controller: 'image-preview' } ) end |