dillonkearns / elm-pages

Hybrid Elm framework with full-stack and static routes.
https://elm-pages.com
BSD 3-Clause "New" or "Revised" License
657 stars 98 forks source link

SetField does nothing #492

Open MattiaVerticchio opened 1 week ago

MattiaVerticchio commented 1 week ago

Hi! First and foremost, thank you for creating elm-pages! 😁

I'm working on a hobby project and implementing a simple suggestion box with autocomplete functionality using the Forms API. My goal is to have a click on a suggestion automatically populate the input field. I tried using the built-in Effect.SetField, but it didn't produce any results.

Upon examining the source code in src/Pages/Internal/Platform.elm, I discovered that this feature hasn't been implemented yet. I'm curious about how this should work. If it's simply a matter of using Dict.insert to add the new value to model.pageFormState, I'd be happy to submit a pull request if you're open to that.

Please let me know your thoughts on this approach or if you have any alternative plans, thank you again!

dillonkearns commented 1 week ago

Hello! Ah yes, you're right, it looks like this isn't implemented:

https://github.com/dillonkearns/elm-pages/blob/5654b80f4db85f471832146559404afc3c081fcb/src/Pages/Internal/Platform.elm#L1009-L1013

I believe the Dict.insert is indeed all it would be. I would gladly accept a PR on that. It would be great to have something in the end-to-end tests for that. Maybe in this test file https://github.com/dillonkearns/elm-pages/blob/master/examples/end-to-end/cypress/e2e/form-submissions.cy.js, which is exercising code in this example Route https://github.com/dillonkearns/elm-pages/blob/5654b80f4db85f471832146559404afc3c081fcb/examples/end-to-end/app/Route/Form.elm. Let me know if you have any questions! Happy to discuss on Slack as well.

Thanks for the issue!