simpleton
2012-Feb-20  19:36 UTC
JS alter a rails form or have rails form variants conditionally on JS?
I have a form with a JavaScript requirement because the page loads a
JS file that creates a form input field with a certain Facebook-
autocomplete kind of style:
<%= javascript_include_tag "form_prettify_library" %>
<div class="box">
	<ul id="first_form" class="tagit"><li
class="prettify-new"></li></ul>
<%= form_for @brand do |f| %>
	<%= f.hidden_field :tag_list, :value =>
@brand.tags_from(current_user).join(", "),
					   :id => "mytaglist" %>
  	<%= f.submit "Add tags" %>
  	<%= f.error_messages %>
<% end %>
</div>
It works well, however without JavaScript the form doesn''t work
because the form above only has a hidden_field and no visible entry
field, and I need this to work without JavaScript. Is there any way to
show the code above if JavaScript is loaded, otherwise the code below
can display?
<div class="box">
<%= form_for @brand do |f| %>
	<%= f.label :tag_list, "Your tags" %>
        <%= f.text_field :tag_list, :value => @brand.all_tags_list %>
        <%= f.submit "Add tags" %>
<% end %>
</div>
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.