Comments (4)
@garyb Agree, UX wise it's not a good idea. Already dropped that idea in my real use case. So no urgency :)
However I thought it's worth mentioning here, because it might be a bug: I checked the example in React and Elm and both work according to my expectation.
In Halogen I tried onValueInput
but the behavior is the same. onValueChange
works after the first enter hit but not after the second.
from purescript-halogen.
You're setting the state to its same value (the value was "x", then you type "xa" and set the state to "x"), so no re-render is happening and the input field is diverging from your state. You'll see the behavior you expect so long as your state is changing. To force a state update even if you're setting the text to its same value, you could add an additional field to your state like this:
type State = { value :: String, force :: Int }
and if you are setting your new state to the same value as is present in the old state, you can also increment force
. This will guarantee a state update and re-render.
from purescript-halogen.
I tried this, here's my modified code:
(...)
initialState :: i -> _
initialState _ = { str: "", num: 0 }
render state =
HH.div []
[ HH.input
[ HA.type_ HA.InputText
, HE.onInput (\event -> (unsafeCoerce event).target.value)
, HA.value state.str
]
, HH.text $ "state: " <> (show state)
]
handleAction (msg :: String) = do
modify_ $ \state -> { str: if msg == "xa" then "x" else msg, num: state.num + 1 }
I am still seeing the same behavior:
from purescript-halogen.
Does it work if you use HE.onValueChange
? I think what's happening is the value is being captured in the event cycle too soon, so you'd have to preventDefault
the event.
Both onValueChange
and onValueInput
give you the new value rather than the Event
also, saving that questionable unsafeCoerce
.
I do have one other thought on this though... don't do it 😄. From a UX perspective preventing input is bad, it's better to allow any input and show a validation message about why it's disallowed instead.
from purescript-halogen.
Related Issues (20)
- `tellAll` function is not re-exported in Halogen module
- Enabling `StateT` with `HalogenM` HOT 1
- Export tellAll from Halogen.Query to Halogen HOT 2
- Reading Effects chapter -> Could not match type ResponseFormat String with type AffjaxDriver HOT 4
- Question: how to handle events coming from a js app? HOT 2
- Communication with JS loaded via CDN HOT 2
- Child component gets rendered outside of parent, being moved to bottom of HTML body HOT 6
- `raise` should not be a blocking operation HOT 8
- Discussion: CSS strategy for halogen applications HOT 20
- Question: body-level events HOT 3
- Order of properties matters when using `value` with `min` / `max` for `InputRange` HOT 3
- Change kind of slots to not be `Type`
- `RenderSpec` doc comment still mentions `h` parameter
- Doc: the examples of "An Aff Example: HTTP Requests" give TypesDoNotUnify Error on Halogen v7 HOT 1
- Select Multiple Selected does not work HOT 4
- Child component is destroyed while parent component handles output from that child HOT 5
- Array state updates HOT 4
- open and showModal are missing for dialog HOT 6
- The Component type should have role annotations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-halogen.