Coder Social home page Coder Social logo

comfy-bootstrap-form's People

Contributors

gbh avatar hovsater avatar ta1kt0me avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

comfy-bootstrap-form's Issues

Models without `error` hash generate `undefined method '[]' for nil:NilClass`

Valid form elements generate undefined method '[]' for nil:NilClass when the form's model does not include an errors hash.

There are some scenarios when rails forms models are not set from an ActiveRecord model. In these scenarios, unless they emulate the errors hash produced by ActiveRecord, the rendering of the form element will result in the aforementioned error.

Example:

<%= bootstrap_form_with(model: my_model) do |f| %>
  <%= f.text_field :top_level_field %>
  <%= f.fields_for :nested_hash, OpenStruct.new(my_model.nested_hash) do |ff| %>
    <%= ff.text_field :nested_hash_field %>
  <% end %>
  <%= f.primary "Save" %>
<% end %>

In this scenario, with vanilla rails form elements, OpenStruct provides all the necessary methods for the nested_hash_field property to be rendered correctly. Using comfy-bootstrap-form this will generate an error unless the nested_hash includes an errors property.

Suggested Fix

The draw_errors method in form_builder.rb already includes a fast-return path if the model is nil. The criteria should this should be expanded to also return if the errors hash is not present.

Fix how radios and checkboxes are generated

Right now I see:

<div class="form-check">
  <label class="form-check-label" for="user_misc_1">
    <input class="form-check-input" type="checkbox" value="1" name="user[misc][]" id="user_misc_1" />
    Foo
  </label>
</div>

<div class="radio">
  <label for="user_misc_1">
    <input type="radio" value="1" name="user[misc]" id="user_misc_1" />
    Foo
  </label>
</div>

Where it should be:

<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
  <label class="form-check-label" for="defaultCheck1">
    Default checkbox
  </label>
</div>

<div class="form-check">
  <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1" checked>
  <label class="form-check-label" for="exampleRadios1">
    Default radio
  </label>
</div>

See: https://getbootstrap.com/docs/4.0/components/forms/#default-stacked

Rework `generate_help` function

  • It's smooshed together with errors display for some reason. Help still should show up on invalid field.
  • I18n for help fields are crammed into active_record namespace for some reason. Seems that forms that are not tied to active_record are not a thing? Will nuke it. Easy enough to add help: t(".help.some_field) that is tied to a view! That would only make sense.

Isolate builder specific options so they don't leak through

Options like layout, label_col, etc need to be wrapped in bootstrap option so they can be contained. Like so

module BootstrapForm
  class FormBuilder
    def initialize(object_name, object, template, options)
      @bootstrap_options = options.delete(:bootstrap)
       super(object_name, object, template, options)
     end
   end
end

Same applies to all helpers. Options like help, etc need to be isolated.

Make label option shortcut

For brevity sake let option :label: { text: "foo" } be the same as label: "foo". It's not often you need to add other properties to labels.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.