|
39 | 39 |
|
40 | 40 | <h2 class="mt-8">All field types</h2> |
41 | 41 |
|
42 | | -<p class="mt-4">Use <code>as:</code> to explicitly set the field type. Supported types: <code>:string</code>, <code>:text</code>, <code>:email</code>, <code>:number</code>, <code>:date</code>, <code>:datetime</code>, <code>:select</code>, <code>:checkbox</code>, and <code>:hidden</code>.</p> |
| 42 | +<p class="mt-4">Use <code>as:</code> to explicitly set the field type. Supported types: <code>:string</code>, <code>:text</code>, <code>:email</code>, <code>:password</code>, <code>:number</code>, <code>:tel</code>, <code>:url</code>, <code>:search</code>, <code>:date</code>, <code>:datetime</code>, <code>:time</code>, <code>:month</code>, <code>:week</code>, <code>:color</code>, <code>:range</code>, <code>:file</code>, <code>:select</code>, <code>:checkbox</code>, and <code>:hidden</code>. The form is automatically rendered as <code>multipart</code> when any field uses <code>:file</code>.</p> |
43 | 43 |
|
44 | 44 | <%= l_ui_form(@post, fields: [ |
45 | 45 | { attribute: :title, as: :string, required: true, placeholder: "Enter a title" }, |
46 | 46 | { attribute: :body, as: :text, hint: "A longer description" }, |
47 | 47 | { attribute: :user_id, as: :select, label: "Author", |
48 | 48 | prompt: "Choose an author", |
49 | 49 | collection: @users.map { |u| [u.name, u.id] } }, |
| 50 | + { attribute: :title, as: :email, label: "Email" }, |
| 51 | + { attribute: :title, as: :password, label: "Password" }, |
| 52 | + { attribute: :user_id, as: :number, label: "Number" }, |
| 53 | + { attribute: :title, as: :tel, label: "Telephone" }, |
| 54 | + { attribute: :title, as: :url, label: "URL" }, |
| 55 | + { attribute: :title, as: :search, label: "Search" }, |
| 56 | + { attribute: :created_at, as: :date, label: "Date" }, |
| 57 | + { attribute: :created_at, as: :datetime, label: "Datetime" }, |
| 58 | + { attribute: :created_at, as: :time, label: "Time" }, |
| 59 | + { attribute: :created_at, as: :month, label: "Month" }, |
| 60 | + { attribute: :created_at, as: :week, label: "Week" }, |
| 61 | + { attribute: :title, as: :color, label: "Color" }, |
| 62 | + { attribute: :user_id, as: :range, label: "Range" }, |
| 63 | + { attribute: :title, as: :file, label: "File" }, |
| 64 | + { attribute: :user_id, as: :checkbox, label: "Checkbox" }, |
| 65 | + { attribute: :user_id, as: :hidden }, |
50 | 66 | ], |
51 | 67 | url: "#") %> |
52 | 68 |
|
|
68 | 84 | { attribute: :user_id, as: :select, label: "Author", |
69 | 85 | prompt: "Choose an author", |
70 | 86 | collection: User.pluck(:name, :id) }, |
| 87 | + { attribute: :email, as: :email }, |
| 88 | + { attribute: :password, as: :password }, |
| 89 | + { attribute: :age, as: :number }, |
| 90 | + { attribute: :phone, as: :tel }, |
| 91 | + { attribute: :website, as: :url }, |
| 92 | + { attribute: :query, as: :search }, |
| 93 | + { attribute: :starts_on, as: :date }, |
| 94 | + { attribute: :starts_at, as: :datetime }, |
| 95 | + { attribute: :starts_time, as: :time }, |
| 96 | + { attribute: :starts_month, as: :month }, |
| 97 | + { attribute: :starts_week, as: :week }, |
| 98 | + { attribute: :tint, as: :color }, |
| 99 | + { attribute: :volume, as: :range }, |
| 100 | + { attribute: :avatar, as: :file }, |
| 101 | + { attribute: :accepted, as: :checkbox }, |
| 102 | + { attribute: :secret_id, as: :hidden }, |
71 | 103 | ], |
72 | 104 | url: posts_path) %></code></pre> |
73 | 105 | </div> |
|
112 | 144 | <td class="l-ui-table__cell">String</td> |
113 | 145 | <td class="l-ui-table__cell">Submit button text (defaults to "Create" for new records, "Save" for persisted records)</td> |
114 | 146 | </tr> |
| 147 | + <tr> |
| 148 | + <th class="l-ui-table__cell l-ui-table__cell--primary" scope="row"><code>multipart:</code></th> |
| 149 | + <td class="l-ui-table__cell">Boolean</td> |
| 150 | + <td class="l-ui-table__cell">Override multipart encoding. Defaults to auto-detection (true when any field is <code>:file</code>). Pass <code>true</code> or <code>false</code> to force.</td> |
| 151 | + </tr> |
115 | 152 | </tbody> |
116 | 153 | </table> |
117 | 154 | </div> |
118 | 155 |
|
| 156 | +<p class="mt-4">Need more control? Override the partial by creating <code>app/views/layered/ui/managed_resource/_form.html.erb</code> in your host app, or write the form directly with <code>form_with</code> and reuse <code>layered_ui/shared/form_errors</code>, <code>layered_ui/shared/label</code>, and <code>layered_ui/shared/field_error</code>.</p> |
| 157 | + |
119 | 158 | <h2 class="mt-8">Field options</h2> |
120 | 159 |
|
121 | 160 | <div class="l-ui-table-container mt-4"> |
|
137 | 176 | <tr> |
138 | 177 | <th class="l-ui-table__cell l-ui-table__cell--primary" scope="row"><code>as:</code></th> |
139 | 178 | <td class="l-ui-table__cell">Symbol</td> |
140 | | - <td class="l-ui-table__cell">Field type (<code>:string</code>, <code>:text</code>, <code>:email</code>, <code>:password</code>, <code>:number</code>, <code>:date</code>, <code>:datetime</code>, <code>:select</code>, <code>:checkbox</code>, <code>:hidden</code>). Inferred from column type when omitted.</td> |
| 179 | + <td class="l-ui-table__cell">Field type (<code>:string</code>, <code>:text</code>, <code>:email</code>, <code>:password</code>, <code>:number</code>, <code>:tel</code>, <code>:url</code>, <code>:search</code>, <code>:date</code>, <code>:datetime</code>, <code>:time</code>, <code>:month</code>, <code>:week</code>, <code>:color</code>, <code>:range</code>, <code>:file</code>, <code>:select</code>, <code>:checkbox</code>, <code>:hidden</code>). Inferred from column type when omitted.</td> |
141 | 180 | </tr> |
142 | 181 | <tr> |
143 | 182 | <th class="l-ui-table__cell l-ui-table__cell--primary" scope="row"><code>label:</code></th> |
|
0 commit comments