Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set or modify input values, instead of only set. #34

Merged
merged 5 commits into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dariooddenino Helper classes that previously used the InputField variant will need to be updated to use the InputFunction variant instead, the only class on the component. The variant was changed to support InputFunction (input -> input) and modification.

=> 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
]
4 changes: 2 additions & 2 deletions example/basic/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ 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 ]
Expand Down
6 changes: 3 additions & 3 deletions example/external-components/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ component =

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
14 changes: 7 additions & 7 deletions example/real-world/Component.purs
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -200,6 +200,6 @@ component =

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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sorts of "toggle" functions are now possible in Formless @whoadave @crcornwell

]
, 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