this repo has no description
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix bug in parsing a sub form with errors

+35 -8
+1 -8
formz/src/formz/formz_use.gleam
··· 17 17 pub type FormItem(format) { 18 18 Item(Input(format)) 19 19 Fieldset(String, List(FormItem(format))) 20 - Section(String, List(FormItem(format))) 21 20 } 22 21 23 22 pub fn with( ··· 118 117 // form was good so far, but this sub form errored, so need to 119 118 // hop on error track 120 119 Ok(_), Error(error_fields) -> 121 - Error([Fieldset(name, error_fields), ..inputs]) 120 + Error([Fieldset(name, error_fields), ..next_inputs]) 122 121 123 122 // form already has errors and this form errored, so add this field 124 123 // to the list of errors ··· 139 138 [Fieldset(_, []), ..rest] -> next_item(rest) 140 139 [Fieldset(name, [first, ..rest_1]), ..rest_2] -> 141 140 next_item(list.flatten([[first], [Fieldset(name, rest_1)], rest_2])) 142 - [Section(_, []), ..rest] -> next_item(rest) 143 - [Section(name, [first, ..rest_1]), ..rest_2] -> 144 - next_item(list.flatten([[first], [Fieldset(name, rest_1)], rest_2])) 145 141 } 146 142 } 147 143 ··· 153 149 case item { 154 150 Item(input) -> Item(fun(input)) 155 151 Fieldset(name, items) -> Fieldset(name, map_items(items, fun)) 156 - Section(name, items) -> Section(name, map_items(items, fun)) 157 152 } 158 153 }) 159 154 } ··· 167 162 [] -> acc 168 163 [Item(input), ..rest] -> do_get_inputs(rest, [input, ..acc]) 169 164 [Fieldset(_, items), ..rest] -> 170 - do_get_inputs(list.flatten([items, rest]), acc) 171 - [Section(_, items), ..rest] -> 172 165 do_get_inputs(list.flatten([items, rest]), acc) 173 166 } 174 167 }
+34
formz/test/formz/formz_use_test.gleam
··· 257 257 |> should.equal(Ok(#(#(1, 2, 3), 4))) 258 258 } 259 259 260 + pub fn sub_form_error_test() { 261 + let f1 = { 262 + use a <- formz.with(field("a", fields.integer_field())) 263 + use b <- formz.with(field("b", fields.integer_field())) 264 + use c <- formz.with(field("c", fields.integer_field())) 265 + 266 + formz.create_form(#(a, b, c)) 267 + } 268 + 269 + let f2 = { 270 + use a <- formz.sub_form("name", "Name", f1) 271 + use b <- formz.with(field("d", fields.integer_field())) 272 + 273 + formz.create_form(#(a, b)) 274 + } 275 + 276 + let assert [inputa, inputb, inputc, inputd] = 277 + f2 278 + |> formz.data([ 279 + #("name.a", "a"), 280 + #("name.b", "2"), 281 + #("name.c", "3"), 282 + #("d", "4"), 283 + ]) 284 + |> formz.parse 285 + |> get_form_from_error_result 286 + |> formz.get_inputs 287 + 288 + inputa |> should_be_field_with_error("Must be a whole number") 289 + inputb |> should_be_field_no_error 290 + inputc |> should_be_field_no_error 291 + inputd |> should_be_field_no_error 292 + } 293 + 260 294 pub fn decoded_and_try_test() { 261 295 let f = 262 296 three_field_form()