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 6824303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:53:08+00:00 2026-05-26T21:53:08+00:00

In my solution at each selected elements on list JavaScript $.get template trought controller.

  • 0

In my solution at each selected elements on list JavaScript $.get template trought controller. It is not optimal. Is there any method to reduce requests? How to DRY for date fields in templates. Maybe exist better solution to get similar effect? I already tried jquery show/hide but hidden forms were also sent I decided to form from templates.

javascript:

$(document).ready(function () {
    $('#meeting_type_id').change(function () {
        var selected = $(this).val();
        if(selected==''){
            $("#time_form").html('');
        }else if(selected=='1' || selected=='2') {
            $.get('meetings/type_form/once', function(data){
                $("#time_form").html(data);
            });
        }else{
            $.get('meetings/time_form/many', function(data){
                $("#time_form").html(data);
            });
        }
        return false;
        // $('#time_form').html("= render (:partial => 'once')");
    });
});

controller:

def time_form
  type = params[:id]
  if type == "once"
    render :partial => 'once'
  else
    render :partial => 'many'
  end
end

templates:

/_once.html.haml/

%input{:name => "meeting[from]", :type => "date", :value => "2011-11-17"

/_many.html.haml/

%input{:name => "meeting[from]", :type => "date", :value => "2011-11-17"
%input{:name => "meeting[to]", :type => "date", :value => "2011-11-17"

view:

= collection_select(:meeting, :type_id, Type.all, :id, :type, :prompt => 'Please select type')
/generates:/
<select id="meeting_type_id" name="meeting[type_id]">
    <option value>Please select type</option>
    <option value="1">once in golf</option>
    <option value="2">once in pub</option>
    <option value="3">many in golf</option>
    <option value="4">many in pub</option>
</select>
<div id="time_form"></div>
  • 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-05-26T21:53:08+00:00Added an answer on May 26, 2026 at 9:53 pm

    You can use only client side:

    $(document).ready(function () {
        $('#meeting_type_id').change(function () {
            var once = '<input type="date" name="meeting[from]" value="2011-11-17"/>';
            var many = '<input type="date" name="meeting[to]" value="2011-11-17"/>';
    
            var selected = $(this).val();
            if(selected==''){
                $("#time_form").html('');
            }else if(selected=='1' || selected=='2') {
                $("#time_form").html(once); 
            }else{
                $("#time_form").html(once+many);
            }
            return false;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope there's a simple solution for this: I have a table where each
I was thinking if there's a better solution for adding onclick handler to each
I have an array of elements assembled by: timeArray = []; $('.time_select').each(function(i, selected) {
Update: Solution below Say you have a list of selected items from Finder. Say
I have a solution consisting of five projects, each of which compile to separate
Here is how our current php development solution is set up: Each developer work
I am wondering about the most elegant solution of having a grid with each
I have a solution ASP.NET MVC where I manage materials with CRUD functionalities. Each
I have a solution with several projects. The projects have references to each other
I have a solution in VS2010 with several projects, each making up a layer

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.