I have a problem with my code below. Essentially, I have a boolean that determines if a client already exists or not - if user says 'yes' shows a previous list of clients using collection_select
- if user says 'no' they get an input field to create a new client using text_field
. JQuery shows or hides the correct input field accordingly.
Problem: When submitting this form, even though JQuery is hiding the field that's not relevant, that field is affecting or preventing the form from being submitted.
For example: If user says 'yes' and chooses an existing client and form is submitted, I get an error message the client_name
is blank (because the form is submitting the blank text_field
instead of what user selected in collection_select
)
Any ideas how I can fix this? Appreciate any help.
<p> Is this new collection for an existing client? </p>
<%= select_tag(:existing_client,options_for_select([['Yes', 1], ['No', 2]], 2), {id: "existing-client"}) %>
<%= f.collection_select :client_name, current_designer.client_folders, :client_name, :client_name, {prompt: true, selected: :id}, {id: "existing-list"} %>
<%= f.text_field :client_name, placeholder: "e.g. Sally Smith", id: "collect-input" %>
Aucun commentaire:
Enregistrer un commentaire