Quick (hopefully) question regarding an implementation. I have created a medical system, that includes patients, doctors, pharmacies etc. When adding a new patient, the form that appears includes a dropdown box that is populated from the doctors database table or pharmacy database table, and when the form is submitted, the doctor/pharmacy id is inserted with the changeset as a foreign key in the patient table. If a new patient arrives and their doctor/pharmacy iis not in the database, this must be made available in order for the patient changeset (and data) to be valid. Therefore before the patient form can be submitted, the doctor/pharmacy details must be registered in the system.
My question is this: How can I implement a way of refreshing the dropdown lists that are populated without losing the data currently on the form?
Well if you are needing to push the updates from the server (much more efficient than polling), then this is probably what you want if you want as much done as possible for you (Itâs awesome):
If you are wanting to poll (less efficient) or just add a few things to HTML tags with almost no work (really, itâs amazing), then a client-side library like this is amazing: https://unpoly.com
The term polling traditionally (in web development) is used for a mechanism in which we request the database for a specific data with a known interval of time (like per second) when we donât know if the new data is arrived or not, typically used in old chat or notification systems. I think unpoly works differently and have a wider usage.
The only definition of âpollingâ that I know if is requesting if there are updates to something in an active fashion, the opposite of which is pushing where the information is pushed over some form of channel.
The way it works (as defined at itâs hex page âaccess the User Interface in the browser directly from the server sideâ), itâs more suited for SSE, which is more efficient if the data flow is uni-directional.
Very different. Drab for each session keeps a process running and it holds the state on the server, the client and that server process talk together to exchange information and perform actions. And as that server process is just a normal websocket connection you can even send messages to it just by broadcasting as normal and all, allowing for almost trivial updates to a webpage.
I looked at the source code, it uses browserâs local storage and session storage to keep the state. So applications like those based on Meteor can easily be made if we use Drab.
Yes, there is a concept of Drab.Store - it is kept on the client side and you may choose if it is on the local storage, session storage or just in the browsers memory.
You may also read values from Plugâs session.
But there is more opportunities to store the values
You can keep the state in assigns. Yes, you can query and update Phoenix assigns, live. So, if you do something like <input type=hidden value=<%= @assign %>, you may get and set this value on the server side with Drab.Live.poke/2 and Drab.Live.peek/2.
value = peek(socket, :assign)
poke(socket, assign: "updated " <> value)
Also, you might just update any property with Drab.element.set_prop/2 and get it back it with Drab.Element.query/3.