amberframework / jasper-helpers

A library of helpers for working with html for apps Crystal
https://amberframework.org
MIT License
19 stars 7 forks source link

check_box behavior #26

Open jaysneg opened 6 years ago

jaysneg commented 6 years ago

check_box helper did not need unchecked_value when using multi params it brake request

why do not left default behavior?

== check_box "gender[]", checked_value: gender.name_to_url, checked: params.fetch_all("gender[]").includes?(gender.name_to_url)

and add somthing like this

62   def input_field_new(type : Symbol, **options)
 63     options = options.to_h
 64     options.delete(:checked) unless options[:checked]
 65     input_field_string(type: type, options: options)
 66   end
faustinoaq commented 6 years ago

@jaysneg Nice idea! @elorest WDYT?

robacarp commented 6 years ago

@jaysneg what do you mean "when using multi params it breaks the request?" Can you provide a more verbose example of what you're trying to do?

jaysneg commented 6 years ago

when you have group of checkboxes.

for example search form with list of brands and you want to select a few and send to server

and at server you will get brands => ["adidas", "0" , "Nike"]

so in this case we don't need unchecked_value

if checkbox unchecked server did not get this parameter

robacarp commented 6 years ago

@jaysneg Great, good example.

Rails uses an option called include_hidden to toggle this behavior, and I think we should follow that pattern. Is that reasonable?

jaysneg commented 6 years ago

@robacarp sounds great