Skip to content

Commit

Permalink
Set select field for enums to empty when isNew
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Sep 14, 2023
1 parent 143c27a commit fd70ef9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion IHP/View/Form.hs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,15 @@ selectField field items = FormField
SelectInput (map itemToTuple items)
, fieldName = cs fieldName
, fieldLabel = removeIdSuffix $ fieldNameToFieldLabel (cs fieldName)
, fieldValue = inputValue ((getField @fieldName model :: SelectValue item))
-- 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
-- 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.
, fieldValue = if isNew model
then ""
else inputValue (getField @fieldName model :: SelectValue item)
, fieldInputId = cs (lcfirst (getModelName @model) <> "_" <> cs fieldName)
, validatorResult = getValidationViolation field model
, fieldClass = ""
Expand Down

0 comments on commit fd70ef9

Please sign in to comment.