Need a little help . . .

37 views
Skip to first unread message

JB

unread,
Jun 12, 2012, 3:54:11 PM6/12/12
to ActiveScaffold : Ruby on Rails plugin
Just wondering what the best way to do something is and was hoping
someone could point me in the right direction. I have a drop down box
on a form. Depending on the value selected I want to hide and/or show
some additional text fields. Any and all thoughts appreciated . . .

Ed Jones

unread,
Jun 12, 2012, 4:05:02 PM6/12/12
to actives...@googlegroups.com
This one has a dropdown for subjects (math, science), and shows a list of courses in the selected subject:

 <%= form_tag('courses/by_subject', :remote => true, :method => "get", :data => { :type => "script" }, :id => 'course_search') do  %>
     <%= select_tag( "subject_id", options_for_select(Subject.all.collect {|p| [ p.name, p.id ] }),:prompt => 'Select Subject' ) %>
 <%= submit_tag "Search" %>
<% end %>
<div id="course_list">
    <%= render 'courses' %>
</div>

You may not need the Subject.all.collect part if you have an array of choices.

Ed

JB

unread,
Jun 12, 2012, 4:17:51 PM6/12/12
to ActiveScaffold : Ruby on Rails plugin
Not quite what I was looking for.

I have a drop down column called Order Type. The available values are
Purchase Order and Change Order.

I have another string column called Owner Change Order Number. I want
this column to be visible on the edit form ONLY if Change Order is
selected for the order type.

Jonas Bang

unread,
Jun 14, 2012, 2:31:44 AM6/14/12
to actives...@googlegroups.com
I'm trying to solve the same issue.

This is what I almost got to work, but it only works once!! Meaning, in a new create form the 'prefix' column is shown, and if I select a 'platform_version' with 'prefix_required' false, then the 'prefix' column will be hidden. But, it does not bring back the 'prefix' column if I change the 'platform_version' to one with 'prefix_required' true. However, with traces in the code I can see that it runs the code and ends up in the 'if' section, but it does not bring back the column.

Could it be that I need to re-render something?

products_controller.rb
config.columns[:platform_version].update_columns = [ :prefix ]

_prefix_form_column.html.erb
<% @tmp_record_id = (params[:eid] || params[:id] || "") %>
<% scope ||= nil %>
<% if @record.prefix_required? %>
  <dl>
    <dt>
      <label for="<%= "record_#{column.name}_#{@tmp_record_id}" %>">
        <%= column.label %>
      </label>
    </dt>
    <dd>
      <%= form_column column, scope %>
    </dd>
  </dl>
<% else %>
<% end %>

Sergio Cambra

unread,
Jun 14, 2012, 3:59:22 AM6/14/12
to actives...@googlegroups.com
In the else part you will have to render something like <dl><dd><span
class="<%= column.name %>-input"></span></dd></dl>

Because render_field action (action called when you change platform_version)
gets the tag with that class, and then gets the dl parent and replace it with
a new one

On Miércoles, 13 de junio de 2012 23:31:44 Jonas Bang escribió:
> I'm trying to solve the same issue.
>
> This is what I almost got to work, but it only works once!! Meaning, in a
> new create form the 'prefix' column is shown, and if I select a
> 'platform_version' with 'prefix_required' false, then the 'prefix' column
> will be hidden. But, it does not bring back the 'prefix' column if I change
> the 'platform_version' to one with 'prefix_required' true. However, with
> traces in the code I can see that it runs the code and ends up in the 'if'
> section, but it does not bring back the column.
>
> Could it be that I need to re-render something?
>
> *products_controller.rb*
> config.columns[:platform_version].update_columns = [ :prefix ]
>
> *_prefix_form_column.html.erb*

Jonas Bang

unread,
Jun 14, 2012, 9:13:33 AM6/14/12
to actives...@googlegroups.com
Thanks, this works perfectly now :o)
We had figured out that we needed some kind of "tag" in the "else" section just couldn't figure out the proper syntax.

Br,
Jonas

JB

unread,
Jun 14, 2012, 10:06:04 AM6/14/12
to actives...@googlegroups.com
You guys are awesome! That's exactly what I was looking for. Much appreciated!
Reply all
Reply to author
Forward
0 new messages