-
Notifications
You must be signed in to change notification settings - Fork 14
How to create a hidden field using the hidden field function
Added for version: 0.4
To add hidden data to your form use the hidden-field function.
The hidden-field function should be used only inside forms. Otherwise, you may not be able to capture the data later.
Hidden-field takes a record, the name of the record, the key in record to get the value from, and optional html-options.
To create a hidden field for a :message record with value “Blah” associated with key :text use:
(hidden-field { :text "Blah" } :message :text)
The above link passes the map { :text “Blah” } as the record to use. More likely, the record you use comes from your database or other model.
The name of the hidden input tag created by hidden-field is “message[text]”, its id is “message-text”, and its value is “Blah”.
You can pass html-options to add attributes to the input tag. To set the hidden field’s id use:
(text-field { :text "Blah" } :message :text { :id "hidden" })