Skip to content
Brendan Huffman edited this page Aug 24, 2020 · 8 revisions

Step 1

  • Form methods defined in form_builder folder
  • file naming convention user_defined_field.rb, module name UserDefinedField, method user_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 an options: {} hash
  • Inheritance structure applied in existing methods

important note about naming convention and inheritance of the super method

  • -> 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 in input 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

Step 2

  • New user defined fields must be prepended in form_builder.rb
  • prepend(UserDefinedField) where UserDefinedField is the module your form method belongs to

Step 3

  • 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 inherited super method mentioned above