2

I have this form:

<div id='relationship_<%= relationship.id %>'>
  <% @value_id = "value_#{relationship.id}" %>
  <% @div_slider_id = "slider_value_#{relationship.id}" %>
  <% @form = "edit_relationship_#{relationship.id}"%>
  <%= form_for(relationship, :remote => true) do |f| %>
    <div id="<%= @div_slider_id %>"></div>
    <%= f.hidden_field :value, :id => "#{@value_id}" %>
  <% end %>
</div>

<script type='text/javascript'>
$(document).ready( function() {
  $(function() {
    $( "#<%= @div_slider_id %>" ).slider({
      orientation: "horizontal",
      range: "min",
      value: <%= relationship.value || 1 %>,
      min: 0,
      max: 100,
      change: function( event, ui ) {
        $( "#<%= @value_id %>" ).val( ui.value );

If the user moves the slider, the form is sent as HTML, not JS

        $("#<%= @form %>").submit();
      }
    });
    $( "#<%= @value_id %>" ).val( $( "#<%= @div_slider_id %>" ).slider( "value" ) );
  });
});
</script>

How do I sent that form on JS format when I move the slider?

thanks

3
  • I don't understand. You couldn't send a JS format but you can as for a JS format. Commented Aug 1, 2012 at 15:16
  • edited my question for clarity Commented Aug 1, 2012 at 15:19
  • Hi, I had the same problem and i posted two questions about that here. It will be sent as html. I solved that problem and wrote the solution in the same post. See if that can help you Commented Aug 1, 2012 at 22:15

2 Answers 2

2

Add an ID to the form submit :

<%= f.submit 'Ready', :id => "button_submit" %>

Then in JS instead of this :

$("#<%= @form %>").submit();

Do

$("#buttom_submit").click();

Or : try adding a data-type to the form declaration :

<%= form_for(relationship, :remote => true, :html => { "data-type" => :js } ) do |f| %>
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the answer, however I actually want to get rid of the button. I'm going to edit the question to make myself clearer.
Edited my answer, try the data-type approach
i ended up using your $("#buttom_submit").click(); approach, and applying a display:none css property to the button. thanks
0
  1. Set relationship_form id to form

2. Change this line in your code :

$("#<%= @form %>").submit();

to

$js.post("/relationship.js", $js("#relationship_form").serialize());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.