reagent-project / reagent-forms

Bootstrap form components for Reagent
339 stars 78 forks source link

Add validation class attribute to container field #62

Closed moskvax closed 9 years ago

moskvax commented 9 years ago

I made this addition as I couldn't see another way to get bootstrap's form validation state styles working.

The implementation is based on event in alert, but with semantics like visible?. The valid? attribute should be a decision function that takes the document atom and returns, for each validation state of the container's children, the name of a class corresponding to that state. The children can then inherit the styles of these classes. For example:

[:form.form-horizontal
 [:div.form-group {:field  :container
                   :valid? #(case (:test-input %)
                                  "yes" "has-success"
                                  "no" "has-error"
                                  "maybe" "has-warning"
                                  nil)}
  [:label.control-label.col-sm-2 {:for :test-input} "yes or no?"]
  [:div.col-sm-9 [:input.form-control {:field :text :id :test-input}]]]]
yogthos commented 9 years ago

looks good :+1:

yogthos commented 9 years ago

and up on clojars

moskvax commented 9 years ago

awesome :beers: