Skip to content
This repository
Browse code

[feature] WFormBuilder: Adding support for initial field values.

  • Loading branch information...
commit c2738ef1b98ed33781f26e3dec453b2fad3de4c9 1 parent 3b9421e
Adam Koprowski akoprow authored

Showing 1 changed file with 12 additions and 6 deletions. Show diff stats Hide diff stats

  1. +12 6 stdlib/widgets/formbuilder/formbuilder.opa
18 stdlib/widgets/formbuilder/formbuilder.opa
@@ -58,8 +58,9 @@ type WFormBuilder.passwd_validator_spec =
58 58 type WFormBuilder.field =
59 59 { id : string
60 60 ; label : string
61   - ; needed : { required } / { optional }
  61 + ; optionality : { required } / { optional }
62 62 ; field_type : { email } / { text } / { passwd } / { desc : { cols: int rows: int} } / { upload }
  63 + ; initial_value : string
63 64 ; validator : WFormBuilder.validator
64 65 ; hint : option(xhtml)
65 66 }
@@ -223,8 +224,9 @@ WFormBuilder =
223 224 @private
224 225 mk_field(label, field_type) : WFormBuilder.field =
225 226 {~label ~field_type
226   - needed={optional}
227 227 id=Dom.fresh_id()
  228 + optionality={optional}
  229 + initial_value=""
228 230 validator=empty_validator
229 231 hint=none
230 232 }
@@ -276,11 +278,14 @@ WFormBuilder =
276 278 set_id(field : WFormBuilder.field, id : string) : WFormBuilder.field =
277 279 {field with ~id}
278 280
  281 + set_initial_value(field : WFormBuilder.field, initial_value : string) : WFormBuilder.field =
  282 + {field with ~initial_value}
  283 +
279 284 make_required(field : WFormBuilder.field, err_msg : xhtml)
280 285 : WFormBuilder.field =
281 286 v = required_validator(err_msg)
282 287 { field with
283   - needed={required}
  288 + optionality={required}
284 289 validator=merge_validators([field.validator, v])
285 290 }
286 291
@@ -348,9 +353,9 @@ WFormBuilder =
348 353 ) : xhtml =
349 354 s = spec.style
350 355 style(style) = WStyler.add(style, _)
351   - mk_field(~{label validator needed field_type id hint}) =
  356 + mk_field(~{label validator optionality initial_value field_type id hint}) =
352 357 req =
353   - match needed with
  358 + match optionality with
354 359 | {optional} -> <span></> |> style(s.non_required_style)
355 360 | {required} -> <span>*</> |> style(s.required_style)
356 361 label_xhtml =
@@ -359,7 +364,8 @@ WFormBuilder =
359 364 {req}
360 365 </> |> style(s.label_style(true))
361 366 input(input_type) =
362   - <input type={input_type} name={input_id(id)} id={input_id(id)} />
  367 + <input type={input_type} name={input_id(id)} id={input_id(id)}
  368 + value={initial_value} />
363 369 input_tag =
364 370 match field_type with
365 371 | {email} -> input("email")

0 comments on commit c2738ef

Please sign in to comment.
Something went wrong with that request. Please try again.