Skip to content

Commit

Permalink
Fixed hiddenField renders a group instead of just the input field
Browse files Browse the repository at this point in the history
Fixes #1626
  • Loading branch information
mpscholten committed Apr 5, 2023
1 parent 4cb3083 commit 9f3e22a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion IHP/View/CSSFramework.hs
Expand Up @@ -69,7 +69,7 @@ instance Default CSSFramework where
DateInput -> styledTextFormField cssFramework "date" formField validationResult
DateTimeInput -> styledTextFormField cssFramework "datetime-local" formField validationResult
CheckboxInput -> styledCheckboxFormField cssFramework formField validationResult
HiddenInput -> styledTextFormField cssFramework "hidden" formField { disableLabel = True, disableGroup = True, disableValidationResult = True } validationResult
HiddenInput -> styledTextFormField cssFramework "hidden" formField validationResult
TextareaInput -> styledTextareaFormField cssFramework formField validationResult
SelectInput {} -> styledSelectFormField cssFramework formField validationResult
FileInput -> styledTextFormField cssFramework "file" formField validationResult
Expand Down
2 changes: 1 addition & 1 deletion IHP/View/Form.hs
Expand Up @@ -594,7 +594,7 @@ hiddenField :: forall fieldName model value.
, InputValue value
, KnownSymbol (GetModelName model)
) => Proxy fieldName -> FormField
hiddenField field = (textField field) { fieldType = HiddenInput }
hiddenField field = (textField field) { fieldType = HiddenInput, disableLabel = True, disableGroup = True, disableValidationResult = True }
{-# INLINE hiddenField #-}

-- | Renders an file field
Expand Down
25 changes: 25 additions & 0 deletions Test/View/CSSFrameworkSpec.hs
Expand Up @@ -97,6 +97,31 @@ tests = do
let textField = baseTextField { additionalAttributes = [ ("min", "1"), ("max", "100") ] }
styledFormField cssFramework cssFramework textField `shouldRenderTo` "<div class=\"mb-3\" id=\"form-group-fname\"><label class=\"form-label\" for=\"fname\">First name:</label><input type=\"text\" name=\"firstname\" placeholder=\"Your firstname\" id=\"fname\" class=\"form-control\" min=\"1\" max=\"100\"> </div>"

describe "hidden field" do
let baseTextField = FormField
{ fieldType = HiddenInput
, fieldName = "workerProfileId"
, fieldLabel = "Worker Profile Id"
, fieldValue = ""
, fieldInputId = "award_workerProfileId"
, validatorResult = Nothing
, additionalAttributes = []
, fieldClass = ""
, labelClass = ""
, disabled = False
, disableLabel = True
, disableGroup = True
, disableValidationResult = True
, cssFramework = cssFramework
, helpText = ""
, placeholder = ""
, required = False
, autofocus = False
}
it "should render without a group and without validation" do
let textField = baseTextField
styledFormField cssFramework cssFramework textField `shouldRenderTo` "<input type=\"hidden\" name=\"workerProfileId\" placeholder=\"\" id=\"award_workerProfileId\" class=\"form-control\"> "


describe "checkbox" do
let baseCheckbox = FormField
Expand Down

0 comments on commit 9f3e22a

Please sign in to comment.