-
Notifications
You must be signed in to change notification settings - Fork 17
Playbook Forms
Brendan Huffman edited this page Aug 24, 2020
·
8 revisions
- Form methods defined in form_builder folder
- file naming convention
user_defined_field.rb
, module nameUserDefinedField
, methoduser_defined(name, **options, props: {})
- new methods accept several arguments, including a name symbol, options hash, and props hash which can be passed onto playbook input kit
-
**options
collects all other key value pairs passed to method and collects them in anoptions: {}
hash - Inheritance structure applied in existing methods
- -> can't inherit without conventional naming:
- form methods inherit a super method which returns an html input tag with attributes parsed from the options hash
- the input tag is in turned passed as a block to the
@template.pbrails()
method which returns the appropriate rails kit - can only be used if your method name follows rails input conventions
- i.e.
def check_box
inherits the super method,def checkbox
does not - unfortunately can't seem to find a list of methods names which will inherit or a way to form inheritance for newly defined, unconventional methods. Seems to be a method for all standard form input fields: checkbox, radio, text_field, date_field, etc.
- luckily it is possible to simply parse your own html attributes and pass them along into an
<input>
string instead of relying solely on the super method to return ininput
variable - in some cases you may wish to pass those html attributes as props to the playbook input kit of your choosing and include logic which applies them to the input within the kit itself
- New user defined fields must be prepended in
form_builder.rb
-
prepend(UserDefinedField)
whereUserDefinedField
is the module your form method belongs to
- Newly defined methods can be tested in doc examples
- add
<%= form.user_defined :name_argument, key1: "opt_value1", key2: "opt_value2", props: { prop_key: "prop_value" } %>
to bottom of form kit - the arguments will be parsed like so
name: name_argument, options: { key1: "opt_value1", key2: "opt_value2"}, props: { prop_key: "prop_value" }
assuming you have made use of the inheritedsuper
method mentioned above