How to remove default input class type from Simple Form, using Rails 4 and Bootstrap 4? -
i'm using rails 4.2.4 bootstrap 4 (using bootstrap_ruby gem).
simple form adds input type classes form... if input string add class string
input. wanted know how stop happening?
for example, if had form file input.
simple_form_for @attachment |f| f.input_field :file, as: :file end
it produce following html:
<form> ... <div class="form-group file optional photo_image"> <label class="file optional control-label" for="attachment_file">file</label> <input class="file optional" type="file" name="attachment[file]" id="attachment_file"></div> ... </form>
it adds file
class label
, input
fields. there way remove file
class when form being built?
i'm trying use bootstrap 4 (alpha) , it's clashing file
class name.
i thought on config.wrappers
adds type of input class eg. string, file
.
thanks in advance.
bootstrap 4's naming choice on custom file field unfortunate, generic. unfortunately, there no easy way toggle automatically added css-classes simpleform.
my solution introduce new input field inherits fileinput, receives different name , different css-class:
// initializer # create new file_hack input type same file class simpleform::inputs::filehackinput < simpleform::inputs::fileinput end # optional: map file_hack input type configuration easier classes etc. simpleform.setup |config| ... config.wrapper_mappings = { # check_boxes: :vertical_radio_and_checkboxes, # radio_buttons: :horizontal_radio_and_checkboxes, # file: :vertical_file_input, file_hack: :vertical_file_input, # boolean: :vertical_boolean } config.wrappers :vertical_file_input, tag: 'fieldset', class: 'form-group', error_class: 'has-error' |b| b.use :html5 b.use :placeholder b.use :label, class: 'control-label' b.wrapper tag: 'div' |ba| ba.use :input, class: 'form-control-file' ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } ba.use :hint, wrap_with: { tag: 'div', class: 'text-muted' } end end
call file field new input "type".
// form = f.input :file, as: :file_hack
Comments
Post a Comment