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

A way to access form element values #10

Open
eamsden opened this issue Aug 12, 2015 · 1 comment
Open

A way to access form element values #10

eamsden opened this issue Aug 12, 2015 · 1 comment

Comments

@eamsden
Copy link

eamsden commented Aug 12, 2015

There is presently no way to access the value of a form element in ghcjs-vdom.

Some ideas considered:

Bundle the value with the change event

This is promising but requires some work to ensure that the value accessor on the event type is referentially transparent. I.e. if a second change event were to fire and the accessor were then called on the Event value handed to the callback the first time, the accessor would return the new value, unless some caching were implemented.

In addition, this requires users of ghcjs-vdom to save the values from change events so that the value can be accessed when desired

Use a Hook to get access to the actual DOM element

virtual-dom allows VNodes to contain Hooks, which are callbacks that are called with the actual DOM element when the VNode is rendered. The main issue with this approach is the question of how to tie a reference to this element back into a change event handler. The change event handler must be attached to the VNode prior to rendering (and a VNode may appear multiple places in the virtual DOM and thus produce multiple elements when patched) while the Hook does not run until patch time. Some form of wormholing (e.g. setting up an IORef where the DOM element will be used and writing to it in the hook) will probably be necessary.

@eamsden
Copy link
Author

eamsden commented Aug 13, 2015

One thing to do with a Hook would be to build a function

customForm :: forall a c . (Attributes a, Children c) => JSString -> a -> c -> (JSRef () -> IO ()) -> VNode

where the hook would set up the callback to be fired when the element was created, and thereafter on each 'change' event, with the current value of the value attribute of the element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant