Usage of select form

Hello everyone!

I have html page, I need to change some values on this page based on chosen value from select form. Select form should be at the beginning of this page. Is there a way to do it?

Thank you for your help!

Are you wanting to set it via a page refresh (Phoenix thing), or are you wanting to do it from inside the web page (Javascript thing, I.E. not related to Phoenix)?

Assuming you are wanting to do it from the Server as this is in the Phoenix section, just put the variable output in the EEX, passed through via an argument to your route, or you can do it dynamically via the Drab library or so thus not requiring a ‘full’ page reload. :slight_smile:

My problem statement wasn’t explained clearly.
I need to refresh page based on selected value.

I think I can’t do it just using variables.

Why not? When a value is selected and submitted to the server then the server receives the value, it can then operate on that value as it wishes, thus displaying anything it wants back to the client. :slight_smile:

1 Like

Thank you for your answers! But I haven’t solved my problem yet.

I have two routes:

scope "/", Web do
  pipe_through :browser

  get "/", GraphController, :index
  post "/", GraphController, :create
end

In controller I have:

def index(conn, _params) do
   namespaces = Repo.all from n in Namespace, select: n.name
   changeset = %Namespace{} |> Namespace.changeset

   render conn, "select.html", [namespace: changeset, namespaces: namespaces]
end

def create(conn, params) do
  render conn, "index.html", namespace: params["namespace"]["name"]
end

select.html.slim template looks like this:

= form_for @namespace, "/", fn f ->
   = select f, :name, @namespaces ,class: "form-control"
   = submit "submit"

But that is not exactly what I need. I need to have select form and index.html content on one page at the same time.

Is it possible ?

Never used slim, but in eex that is trivial and is how it works by default, you just render whatever other templates into a page passing in whatever arguments as needed.