You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -102,17 +84,11 @@ With the above preparation done, you can use Fable.Form.Simple.Bulma in your `./
102
84
103
85
1. Create type `Values` to represent each input field on the form (a single textbox), and create a type `Form` which is an alias for `Form.View.Model<Values>`:
104
86
105
-
=== "Code"
106
-
``` { .fsharp title="Index.fs" }
107
-
type Values = { Todo: string }
108
-
type Form = Form.View.Model<Values>
109
-
```
110
87
111
-
=== "Diff"
112
-
``` { .diff title="Index.fs" }
113
-
+type Values = { Todo: string }
114
-
+type Form = Form.View.Model<Values>
115
-
```
88
+
``` { .fsharp title="Index.fs" }
89
+
type Values = { Todo: string }
90
+
type Form = Form.View.Model<Values>
91
+
```
116
92
117
93
1. In the `Model` type definition, replace `Input: string` with `Form: Form`
118
94
@@ -215,100 +191,60 @@ With the above preparation done, you can use Fable.Form.Simple.Bulma in your `./
215
191
216
192
1. Create `form`. This defines the logic of the form, and how it responds to interaction:
217
193
218
-
=== "Code"
219
-
``` { .fsharp title="Index.fs" }
220
-
let form : Form.Form<Values, Msg, _> =
221
-
let todoField =
222
-
Form.textField
223
-
{
224
-
Parser = Ok
225
-
Value = fun values -> values.Todo
226
-
Update = fun newValue values -> { values with Todo = newValue }
227
-
Error = fun _ -> None
228
-
Attributes =
229
-
{
230
-
Label = "New todo"
231
-
Placeholder = "What needs to be done?"
232
-
HtmlAttributes = []
233
-
}
234
-
}
235
-
236
-
Form.succeed AddTodo
237
-
|> Form.append todoField
238
-
```
239
-
240
-
=== "Diff"
241
-
``` { .diff title="Index.fs" }
242
-
+let form : Form.Form<Values, Msg, _> =
243
-
+ let todoField =
244
-
+ Form.textField
245
-
+ {
246
-
+ Parser = Ok
247
-
+ Value = fun values -> values.Todo
248
-
+ Update = fun newValue values -> { values with Todo = newValue }
249
-
+ Error = fun _ -> None
250
-
+ Attributes =
251
-
+ {
252
-
+ Label = "New todo"
253
-
+ Placeholder = "What needs to be done?"
254
-
+ HtmlAttributes = []
255
-
+ }
256
-
+ }
257
-
+
258
-
+ Form.succeed AddTodo
259
-
+ |> Form.append todoField
260
-
```
194
+
``` { .fsharp title="Index.fs" }
195
+
let form : Form.Form<Values, Msg, _> =
196
+
let todoField =
197
+
Form.textField
198
+
{
199
+
Parser = Ok
200
+
Value = fun values -> values.Todo
201
+
Update = fun newValue values -> { values with Todo = newValue }
202
+
Error = fun _ -> None
203
+
Attributes =
204
+
{
205
+
Label = "New todo"
206
+
Placeholder = "What needs to be done?"
207
+
HtmlAttributes = []
208
+
}
209
+
}
210
+
211
+
Form.succeed AddTodo
212
+
|> Form.append todoField
213
+
```
261
214
262
-
1. In the function `containerBox`, remove the existing form view. Then replace it using `Form.View.asHtml` to render the view:
215
+
1. In the function `todoAction`, remove the existing form view. Then replace it using `Form.View.asHtml` to render the view:
263
216
264
217
=== "Code"
265
-
``` { .fsharp title="Index.fs" }
266
-
let containerBox (model: Model) (dispatch: Msg -> unit) =
267
-
Bulma.box [
268
-
Bulma.content [
269
-
Html.ol [
270
-
for todo in model.Todos do
271
-
Html.li [ prop.text todo.Description ]
272
-
]
273
-
]
274
-
Form.View.asHtml
275
-
{
276
-
Dispatch = dispatch
277
-
OnChange = FormChanged
278
-
Action = Form.View.Action.SubmitOnly "Add"
279
-
Validation = Form.View.Validation.ValidateOnBlur
280
-
}
281
-
form
282
-
model.Form
283
-
]
284
-
```
285
-
218
+
``` { .fsharp title="Index.fs" }
219
+
let private todoAction model dispatch =
220
+
Form.View.asHtml
221
+
{
222
+
Dispatch = dispatch
223
+
OnChange = FormChanged
224
+
Action = Action.SubmitOnly "Add"
225
+
Validation = Validation.ValidateOnBlur
226
+
}
227
+
form
228
+
model.Form
229
+
```
286
230
=== "Diff"
287
-
``` { .diff title="Index.fs" }
288
-
let containerBox (model: Model) (dispatch: Msg -> unit) =
With the basic structure in place, it's easy to add functionality to the form. For example, the [changes](https://github.com/CompositionalIT/safe-fable-form/commit/6342ee8f4abcfeed6dd5066718e6845e6e2174d0) necessary to add a high priority checkbox are pretty small.
250
+
With the basic structure in place, it's easy to add functionality to the form. For example, the [changes](https://github.com/CompositionalIT/safe-fable-form/commit/6342ee8f4abcfeed6dd5066718e6845e6e2174d0) necessary to add a high priority checkbox are pretty small.
0 commit comments