Is there any helper method available which shows/hides specified div based on the value of a model attribute?
Here is the partial where I want to show div that wraps openid_domain_name
text field if openid_enabled
is true
and hide otherwise while editing record.
<%= form_for @application do |f| %>
<%= render "shared/error_messages", target: @application %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :description %>
<%= f.text_field :description %>
<%= f.check_box :openid_enabled %>
<%= f.label 'openid', 'OpenID' %>
<%= f.submit class: "btn btn-primary" %>
<% end %>
Here is the javascript that shows/hides the div when user checks/unchecks the check box.
EDITED
Generated HTML Source:
Answer
I have written custom helper to do the same. Please suggest if it is correct solution or not.
app/helper/application_helper.rb
def show_hide(show)
show ? 'block' : 'none'
end
app/views/applications/_form.html.erb
<%= f.label :openid_domain_name %>
<%= f.text_field :openid_domain_name %>
No comments:
Post a Comment