element
accessor. You can even scoop up the attributes of parent elements. This leaves form submission in the cold, though... doesn't it? 🥶form
element - or a child of that form
element - then the data for the whole form will be serialized and made available to the Reflex action method as the params
accessor.params
is an instance of ActionController::Parameters
which you can manipulate the same way you would with a real form submitted via a normal POST action, with require
and permit
. This is useful for validating models and setting multiple attributes of a model at the same time, even if it hasn't yet been saved to the datastore.form
elements as a familiar way to group related elements together. However, a lot of newcomers get attached to the idea that the form they are serializing is being used as an HTML form, which it is not.<form></form>
with no other mechanism or configuration requiredparams
before its sent to the serverparams
in your beforeReflex
callback by modifying element.reflexData[reflexId]
before it is sent to the server.serializeForm: false
as one of the possible optional arguments to the stimulate
method.params
accessor in your Reflex classparams
accessor is available to your before_reflex
around_reflex
and after_reflex
callbacks in your server-side Reflex class. You are also free to add additional business logic on the client using the Reflex life-cycle callbacks in your Stimulus controllers.params
accessor behaves as it does in a Rails controller, so you are free to lock it down and add nested models as you expect:@post
object is instantiated from params
so if model validations fail, your Post model instance is still in scope when the page re-renders. The model's errors
collection is available in the view. 🐛data-reflex="change->Post#update"
to each field. Since the field is inside the parent form
element, all inputs are automatically serialized and sent to your Reflex class.has_many
associations? No sweat! Building a new record for a nested model requires no JavaScript. Your Reflex calls @post.comments.build
and because Rails knows about the association, any re-renders populate the empty form field as normal.params
accessor, pointing to an empty ActionController::Parameters
instance.data-reflex-permanent
so that you don't lose UI state when a Reflex is triggered.<input>
fields. You're going to need to clear your form so the user can add more data.reflex-form
and we'll use it to set a target on the first text field, as well as an action on the submit button:Post
Reflex with a signed global ID.@post
object is created from the params
in the before_reflex
callback, users can click New comment many times to get new empty comments.data-reflex-permanent
will not be morphed in any way.inner_html
operation. The client-side logger will show you which operation is being used, and you can tweak the data you're sending to make sure it's delivered as a morph
operation.data-reflex-permanent
. You can set the permanent_attribute_name
option for the morph operation directly.form
context, since it's not just a simple view helper that you can include.morph
the HTML content required to successfully update the children of your target element. This requires that the outermost element of the supplied HTML matches the parent element:div
, in order to successfully replace the contents of "form_swap" we'll need to wrap it ourselves: