-
Notifications
You must be signed in to change notification settings - Fork 14
How to create a textfield using the text field function
Added for version: 0.4
You’ve created your form, and now you want to allow a user to input text? Use the text-field function.
The text-field function should be used only inside forms. Otherwise, you may not be able to capture the user input.
Text-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 text field for a :message record with value “Blah” associated with key :text use:
(text-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 text input tag created by text-field is “message[text]”, the id of the input tag is “message-text”, and the value of the input tag is “Blah”.
You can pass html-options to add attributes to the input tag. To set the text field to read only use:
(text-field { :text "Blah" } :message :text { :readonly "readonly" })