Beaker API
Beaker is Formula's API that helps with the creation of multi-row forms using lists of data (e.g. contact or product list).
Beaker is still in active development - as such there may still be API changes
Under-the-hood it uses Formula to create a form from a row of data provided, and works well with Svelte's {#each}
blocks to render the form component.
When creating a group it's possible to set any existing data, and add and remove rows in the store using helper methods, and using the store to render the component HTML.
#
UsageLike formula
you import the beaker
function. This function returns an object that is the entire group functionality.
To bind the group to a component pass <myGroup>.group
to use
, then inside the group provide an {#each}
block that
will contain the template for your group form.
Stores are available via <myGroup>.stores
object - the names are the same as the Formula Stores
- the main difference is that the data is an Array of objects instead of a single object.
#
Adding and Removing itemsAdding and removing items to the store is easy - there is a data api for handling data.
You can initialise a group with <myGroup>.init(items)
passing an array of items for your form group to be initialised
with.
To add another item call <myGroup>.add(item)
with your item to add. To remove an item call <myGroup>.delete(index)
with the numerical index of the array item to remove.
radio
groups#
Note about Due to the way HTML Radio Groups work it is
required to have unique names as well as ID properties in your HTML. To support this you can provide a data-formula-name
attribute on any radio groups - this will match the group back to the correct data.