Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Sep 16, 2023
1 parent 65c22eb commit 8cd5e53
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion IHP/View/Form.hs
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,12 @@ selectField field items = FormField
FormContext { model } = ?formContext
-- The select field is always displaying the value it gets from the nodel passed to the formFor.
-- The issue is introduced basically by the `newRecord @Record`. The `newRecord` call in the controller creates an empty record setting all fields to a default empty value.
-- The default empty value for UUIDs is the 00000000-0000-0000-0000-000000000000 and the default empty value for
-- The default empty value for UUIDs is the 00000000-0000-0000-0000-000000000000 and the default empty value for
-- enums is the first enum value.
-- Now, if we have a required field, we want to make sure the user selects a value, in the same
-- way they have to select for a reference field.
-- So we check if the model is new and the field was not submitted yet, then we set the
-- field value to an empty string. Otherwise, we use the value from the model.
fieldValue = if isNew model && null (paramList @Text (cs fieldName))
then ""
else inputValue (getField @fieldName model :: SelectValue item)
Expand Down

0 comments on commit 8cd5e53

Please sign in to comment.