Skip to content

Commit

Permalink
Merge pull request #34 from thomashoneyman/modify-set
Browse files Browse the repository at this point in the history
Add ability to set or modify input values, instead of only set.
  • Loading branch information
thomashoneyman committed Oct 20, 2018
2 parents f02ba82 + 0fbdfe8 commit 73e4a89
Show file tree
Hide file tree
Showing 20 changed files with 1,053 additions and 772 deletions.
6 changes: 3 additions & 3 deletions example/App/UI/Element.purs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ formlessField
. IsSymbol sym
=> ToText e
=> Newtype (form Record F.FormField) (Record fields)
=> Newtype (form Variant F.InputField) (Variant inputs)
=> Newtype (form Variant F.InputFunction) (Variant inputs)
=> Cons sym (F.FormField e String o) t0 fields
=> Cons sym (F.InputField e String o) t1 inputs
=> Cons sym (F.InputFunction e String o) t1 inputs
=> ( FieldConfig'
-> Array ( HH.IProp
( value :: String, onBlur :: FocusEvent, onInput :: Event | r)
Expand All @@ -183,5 +183,5 @@ formlessField fieldType config state = fieldType (Builder.build config' config)

props =
[ HP.value (F.getInput config.sym state.form)
, HE.onValueInput $ HE.input $ F.modifyValidate config.sym
, HE.onValueInput $ HE.input $ F.setValidate config.sym
]
6 changes: 3 additions & 3 deletions example/basic/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ renderFormless state =
, placeholder: "Dale"
}
[ HP.value $ F.getInput _name state.form
, HE.onValueInput $ HE.input $ F.modifyValidate _name
, HE.onValueInput $ HE.input $ F.setValidate _name
]
, UI.textarea
{ label: "Message"
, help: Right "Write us a message"
, placeholder: "We prefer nice messages, but have at it."
}
[ HP.value $ F.getInput _text state.form
, HE.onValueInput $ HE.input $ F.modify _text
, HE.onValueInput $ HE.input $ F.set _text
]
, UI.buttonPrimary
[ HE.onClick $ HE.input_ F.Submit ]
[ HE.onClick $ HE.input_ F.submit ]
[ HH.text "Submit" ]
]
where
Expand Down
8 changes: 4 additions & 4 deletions example/external-components/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ component =
_ <- H.query unit $ F.send Email (H.action TA.Clear)
_ <- H.query unit $ F.send Whiskey (H.action TA.Clear)
_ <- H.query unit $ F.send Language (H.action TA.Clear)
H.query unit $ H.action F.ResetAll
H.query unit F.resetAll_

Typeahead slot (TA.SelectionsChanged new) a -> case slot of
Email -> a <$ do
H.query unit $ F.modifyValidate_ prx.email new
H.query unit $ F.setValidate_ prx.email new

Whiskey -> a <$ do
_ <- H.query unit $ F.modifyValidate_ prx.whiskey new
_ <- H.query unit $ F.setValidate_ prx.whiskey new
-- We'll clear the email field when a new whiskey is selected
_ <- H.query unit $ F.reset_ prx.email
H.query unit $ F.send Email (H.action TA.Clear)

Language -> a <$ do
H.query unit $ F.modifyValidate_ prx.language new
H.query unit $ F.setValidate_ prx.language new
2 changes: 1 addition & 1 deletion example/external-components/RenderForm.purs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ formless state =
[ UI.buttonPrimary
[ if state.submitting || state.validity /= F.Valid
then HP.disabled true
else HE.onClick $ HE.input_ F.Submit
else HE.onClick $ HE.input_ F.submit
]
[ HH.text "Submit" ]
, UI.button
Expand Down
22 changes: 11 additions & 11 deletions example/real-world/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ component =
_ <- H.query' CP.cp1 unit $ F.send' CP.cp3 unit (H.action DD.Clear)
-- If there is only one child type, use Send
_ <- H.query' CP.cp2 unit $ F.send unit (H.action DD.Clear)
_ <- H.query' CP.cp1 unit $ H.action F.ResetAll
_ <- H.query' CP.cp2 unit $ H.action F.ResetAll
_ <- H.query' CP.cp1 unit F.resetAll_
_ <- H.query' CP.cp2 unit F.resetAll_
pure a

-- On submit, we need to make sure both forms are run. We
Expand Down Expand Up @@ -156,22 +156,22 @@ component =
pure a

TASingle (TA.SelectionsChanged new) a -> a <$ do
H.query' CP.cp1 unit $ F.modifyValidate_ G.prx.whiskey new
H.query' CP.cp1 unit $ F.setValidate_ G.prx.whiskey new

TAMulti slot (TA.SelectionsChanged new) a -> a <$ case slot of
Applications ->
H.query' CP.cp1 unit $ F.modifyValidate_ G.prx.applications new
H.query' CP.cp1 unit $ F.setValidate_ G.prx.applications new
Pixels ->
H.query' CP.cp1 unit $ F.modifyValidate_ G.prx.pixels new
H.query' CP.cp1 unit $ F.setValidate_ G.prx.pixels new

AdminDropdown m a -> a <$ do
_ <- H.query' CP.cp1 unit $ F.reset_ G.prx.secretKey1
_ <- H.query' CP.cp1 unit $ F.reset_ G.prx.secretKey2
case m of
DD.Selected x -> do
H.query' CP.cp1 unit $ F.modifyValidate_ G.prx.admin (Just x)
H.query' CP.cp1 unit $ F.setValidate_ G.prx.admin (Just x)
DD.Cleared -> do
H.query' CP.cp1 unit $ F.modifyValidate_ G.prx.admin Nothing
H.query' CP.cp1 unit $ F.setValidate_ G.prx.admin Nothing

-----
-- Options Form
Expand All @@ -193,13 +193,13 @@ component =
case st'.optionsEnabled of
true -> do
let spec' = O.OptionsForm $ _ { enable = F.InputField true } $ unwrap optionsFormInputs
void $ H.query' CP.cp2 unit $ H.action $ F.ReplaceInputs spec'
void $ H.query' CP.cp2 unit $ F.initialize_ spec'
_ -> do
void $ H.query' CP.cp2 unit $ H.action $ F.ReplaceInputs defaultInputs
void $ H.query' CP.cp2 unit $ F.initialize_ defaultInputs
pure a

MetricDropdown m a -> a <$ case m of
DD.Selected x -> do
H.query' CP.cp2 unit $ F.modifyValidate_ O.prx.metric (Just x)
H.query' CP.cp2 unit $ F.setValidate_ O.prx.metric (Just x)
DD.Cleared -> do
H.query' CP.cp2 unit $ F.modifyValidate_ O.prx.metric Nothing
H.query' CP.cp2 unit $ F.setValidate_ O.prx.metric Nothing
4 changes: 2 additions & 2 deletions example/real-world/Render/GroupForm.purs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ renderSecretKey1 st =
}
[ HP.value $ F.getInput prx.secretKey1 st.form
, HE.onValueInput $ HE.input \str -> F.AndThen
(F.modifyValidate_ prx.secretKey1 str)
(F.setValidate_ prx.secretKey1 str)
(F.validate_ prx.secretKey2)
]

Expand All @@ -74,7 +74,7 @@ renderSecretKey2 st =
}
[ HP.value $ F.getInput prx.secretKey2 st.form
, HE.onValueInput $ HE.input \str -> F.AndThen
(F.modifyValidate_ prx.secretKey2 str)
(F.setValidate_ prx.secretKey2 str)
(F.validate_ prx.secretKey1)
]

Expand Down
8 changes: 4 additions & 4 deletions example/real-world/Render/OptionsForm.purs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ renderEnabled state =
[ css "checkbox"
, HP.type_ InputCheckbox
, HP.checked $ F.getInput prx.enable state.form
, HE.onChange $ HE.input_ $ F.modify prx.enable (not $ F.getInput prx.enable state.form)
, HE.onChange $ HE.input_ $ F.modify prx.enable not
]
, HH.text " Enable extra options"
]
Expand Down Expand Up @@ -149,7 +149,7 @@ renderSpeed state =
, css "radio"
, HP.type_ InputRadio
, HP.checked $ speed.input == Low
, HE.onClick $ HE.input_ $ F.modify prx.speed Low
, HE.onClick $ HE.input_ $ F.set prx.speed Low
]
, HH.text $ " " <> show Low
]
Expand All @@ -160,7 +160,7 @@ renderSpeed state =
, css "radio"
, HP.type_ InputRadio
, HP.checked $ speed.input == Medium
, HE.onClick $ HE.input_ $ F.modify prx.speed Medium
, HE.onClick $ HE.input_ $ F.set prx.speed Medium
]
, HH.text $ " " <> show Medium
]
Expand All @@ -171,7 +171,7 @@ renderSpeed state =
, css "radio"
, HP.type_ InputRadio
, HP.checked $ speed.input == Fast
, HE.onClick $ HE.input_ $ F.modify prx.speed Fast
, HE.onClick $ HE.input_ $ F.set prx.speed Fast
]
, HH.text $ " " <> show Fast
]
Expand Down
Loading

0 comments on commit 73e4a89

Please sign in to comment.