Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:24:28+00:00 2026-06-09T20:24:28+00:00

Is there any helper method available which shows/hides specified div based on the value

  • 0

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 %>
    <p>
      <%= f.label :name %>
      <%= f.text_field :name %>
    </p>
    <p>
      <%= f.label :description %>
      <%= f.text_field :description %>
    </p>   
    <p>
      <%= f.check_box :openid_enabled %>
      <%= f.label 'openid', 'OpenID' %>
      <div id="application_openid_domain" style="display: none;">
        <%= f.label :openid_domain_name %>
        <%= f.text_field :openid_domain_name %>
      </div>
    </p>
    <p><%= f.submit class: "btn btn-primary" %></p>
<% end %>

Here is the javascript that shows/hides the div when user checks/unchecks the check box.

<script type="text/javascript">
     $(function() {
        $(':checkbox').click(function () {
          if ($(this).is(':checked'))
            $("#application_openid_domain").show();
          else
            $("#application_openid_domain").hide();            
        });
    });
</script>

EDITED
Generated HTML Source:

<form accept-charset="UTF-8" action="/applications" class="new_application" id="new_application" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="Cq2rYF1qkjnsobimMTAUvle9Hi82LwdvghcVWRtC/I0=" /></div>
  <p>
    <label for="application_name">Name</label>
    <input id="application_name" name="application[name]" size="30" type="text" />
  </p>
  <p>
    <label for="application_description">Description</label>
    <input id="application_description" name="application[description]" size="30" type="text" />
  </p>
  <p>
    <input name="application[openid_enabled]" type="hidden" value="0" /><input id="application_openid_enabled" name="application[openid_enabled]" type="checkbox" value="1" />
    <label for="application_openid">OpenID</label>
    <div id="application_openid_domain" style="display: none;">
      <label for="application_openid_domain_name">Openid domain name</label>
      <input id="application_openid_domain_name" name="application[openid_domain_name]" size="30" type="text" />
    </div>
  </p>
  <p><input class="btn btn-primary" name="commit" type="submit" value="Create Application" /></p>
</form>

<script type="text/javascript">
     $(function() {
        $(':checkbox').click(function () {
          if ($(this).is(':checked'))
            $("#application_openid_domain").show();
          else
            $("#application_openid_domain").hide();            
        });
    });
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:24:30+00:00Added an answer on June 9, 2026 at 8:24 pm

    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

    <div id="application_openid_domain" style="display: <%= show_hide(@application.openid_enabled?)%>;">
      <%= f.label :openid_domain_name %>
      <%= f.text_field :openid_domain_name %>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to use a Rails helper method, more specifically, a path
Is there any helper method (Other than default rails breadcrumb ) that generates bread
is there any sort of control for .net mvc 3 (some html helper method
I want to write a little helper method which returns the base URL of
I have a helper method in Magento which requires me to get the count
I've a view helper method which generates a url by looking at request.domain and
Is there any way I can add this to my plugin? $this->_helper->viewRenderer->setNoRender();
Is there any functional difference in Python between a try statement and an if
Is there any way in Notepad++ (or even with another tool) to change the
Is there any way I can set a formatter on models that will convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.