carlosarli
Hello,
I am a complete jasvascript newbie so please bear with me.
I am using fullcalnedar.io to render a calendar in one of my views and I would like to prompt the new action from my appointment controller when I click on a date on the calendar. So i have to create a function that corresponds to the dayClick helper from the api that calls the new action in the controller and passes to it the start and end date. I know how to get the start date and the other details in javascrit I just don’t know how to make the call. should I use ajax? if so could you give me an example of how you would do it that I coul use as an example for then my other actions such as edit?
Thank you very much for your patience
Carlo
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
You can read about making requests from js using
XMLHttpRequesthere orfetchhere.For
XMLHttpRequestit would be something like this, probably (adapted from https://stackoverflow.com/questions/9713058/send-post-data-using-xmlhttprequest)And for
fetch(adapted from https://stackoverflow.com/questions/29775797/fetch-post-json-data)peerreynders
Doing what exactly?
You have to understand that once the page is loaded in the browser there is no inherent “connection” between the browser page and the Phoenix controller.
In
dayClickyou could simply set something liketo navigate to a new page (see
Window.location).If you have your routes set up something like this:
then that request would be routed to the
DateControllerto generate the new page which would then be loaded in the browser.carlosarli
Hi, thanks for taking the time, I really appreciate it
I have set up everything like a normal crud app so my appointments have a form and the usual templates that call it with different parameters. I wanted to be able to click on a calendar day and prompt up the form with the dates already filled in corresponding to the day that I clicked. Now the ultimate goal woud be to have a small partial directly into the page with ajax but for now I’d be happy to click on a day and just get redirected to the form in a new page with hte relevant information preloaded.
Does that make my question a tad clearer? I am sorry for the messiness of the first post
kokolegorille
If You just want to be redirected, You could use a normal link instead of a js link, passing some parameters along.
The idea of js link is not to have the page reloaded. You make a request, with fetch or ajax, and you receive data. With this data, You still need to update the Dom to reflect changes. This can be done by jquery, or vanilla js.
For your use case, I would look at drab library.
peerreynders
Sounds like you want something like a modal rather than a submittable
form.See Considerations for Styling a Modal (demo) to see how the HTML/CSS/JS elements interact to achieve the basic desired result with vanilla JS. Of course you are going to still have to add:
dayClickcode to fetch the data from Phoenix withfetch(some people preferaxios)For improved performance you may want to consider having all the detailed information relating to any dates already on the screen inside the browser so that you can grab the information from there and only send the changes back to Phoenix while you update your local copy.
For example TodoMVC maintains an array of todo objects as a model (though in your case use of
LocalStoragewould be overkill) - any information in the DOM is simply a copy of information inside that client side model.There is an example todo backend implementation with an older version of Phoenix here (demo).
In particular look at the
router.exandtodo_controller.ex.In general I wouldn’t pay any attention to the JavaScript client used here because it’s ancient. It uses Backbones.js fetch.
carlosarli
Hey,
Thanks for the help
I’m looking into drab as it seems like a good way to limit the amount of js to write (not a big fan I’m afraid). I was wondering if i get how it works more or less correctly: Am I right in saying that I could assign to the dayClick event a call to a drab controller to which I pass the relevant data from the dom and then use the drab controller to call a the usual phoenix controller?
In this case i would say that I click on a day on the calendar, get the relevant dates, pass them on to the drab controller and then call the new action in the controller from there?
Thank you
carlosarli
BTW I solved my issue by using HTML local storage to pass the datetime data from the calendar to the form
thank you all for the help!