简体   繁体   中英

Generating text_input after selecting “Other” on Phoenix form

I am trying to generate a text_input in Phoenix.HTML for a form field after a user selects "Other" from my dropdown <select> , but I'm unsure of the syntax for doing so in Phoenix markup

I imagine it is something with an if or case statement, perhaps in the opts for select, but again I am unsure

<div class="form-group">
<%= label f, :field, class: "control-label" %>
<%= select f, :field, [..."Other"], prompt: "Select your field", class: "form-control" %>
<%= error_tag f, :field %>
<%= if "Other" do %>
  <%= text_input f, :field, class: "form-control" %>
<% end %>

Thanks for reading!

I don't think it's possible. What you may do is to always generate this field but hide it (using css) before it's required and then just use some JS to show it when it's needed or skip generating on the server side at all and do it on the client side, again with help of JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM