How to get the form value of a drop-down field in a simple form object BEFORE form submission

75 views
Skip to first unread message

Bharat

unread,
May 29, 2013, 11:52:22 AM5/29/13
to plataformate...@googlegroups.com
Here is a snippet of my code for a bootstrap enabled simple_form partial which is rendered from both new.html.haml and edit.html.haml:

.well
  = simple_form_for @scenario, :html => { :class => 'scenario_form' } do |f|
    %fieldset#economics
      %legend Economics
      .row
        .span4
          = f.input :pdeck_id, :collection => @pdecks.map { |p| [p.name, p.id] }, :label => "Price Deck"
        .span4
          = link_to 'Display a Bootstrap Modal for the selected pdeck_id when clicked', :class => 'btn', :remote => true, :id => ???
    .row
      .span4
        = submit_tag 'Save', :class => 'btn btn-primary'

I need to get hold of the price deck id (pdeck_id above in my code) when the link is clicked in BOTH the new and edit actions, so that I can then activate a remote bootstrap popup showing all the details for that price deck.  The reason this is necessary is that just the price deck name is not enough for the user.  They need to be able to see the other details for the selected Price Deck so that they know that the correct deck is being selected.  I would like to make this a 'remote' link and be able to pass in the selected pdeck_id with the id attribute.

Appreciate any help in advance.

Bharat

Andrew Havens

unread,
Jun 28, 2013, 5:37:45 PM6/28/13
to plataformate...@googlegroups.com
Bharat,

You need to use some javascript to accomplish this. Something like this:

$('.display_pdecks_modal').click(function(){
  var pdeck_id = $('select#pdeck_id option:selected').val();
  // trigger modal here
});
Reply all
Reply to author
Forward
0 new messages