ujs

Rails UJS confirm box cancel button callback

允我心安 提交于 2019-12-10 14:57:00
问题 I am using Rails jquery ujs for handling ajax within my app. Also I am using a the confirm option for destroying any records. As my current setup, I have hooked up a loading overlay screen on click of data-remote=true link. All I wanted to know is: Is there a way I can hook a callback event when a user clicks cancel on the confirm box and I can close the loader overlay. 回答1: Yes, you can. Pass in the response object. In CoffeeScript. $('selector').on 'confirm:complete', (e, response) -> if

Rails: cannot submit a remote form that was loaded via Ajax

余生长醉 提交于 2019-12-07 02:30:24
问题 Goal I have a page with a list of items, coming from a Rails backend. I want to be able to edit a row in that list, using Ajax calls via Rails UJS. Approach I've added an edit button to the end of each row. The edit button is a link_to ... :remote => true . Clicking it loads the list again, but with the selected row in edit mode. The editable row is embedded in a form ... :remote => true . The save button in that row is a submit button. index.html.haml #editor %table - @items.each do |item|

Rails unobtrusive javascript (UJS) ajax:before append data params

不羁岁月 提交于 2019-12-06 11:29:32
I'm trying to append some parameters to a form before sending via ajax (via Rails UJS). $(document).on("ajax:before",".form-example", function(event) { event.data = $(":hidden").serialize(); }); The hidden inputs aren't within the form, so I need to collect them, serialize the, and add them to the request (which is a PUT request). However, in the above example, no parameters are being passed to the server, am I doing something wrong? How can I pass parameter called "items" with the serialized values of hidden inputs? Looking into this, it is actually possible to do, but you do not use the

Turbolinks causes a link with href=“#” to trigger page refresh

独自空忆成欢 提交于 2019-12-06 06:20:22
问题 I have a very simple link on my page. <a href="#">My link</a> . It causes a page refresh. when I remove "turbolinks", it no longer causes a refresh. I've used links with hash fragments all the time in the past. Unless I've missed something very fundamental for a long time, I don't understand how this can cause a refresh. It does not have any JS event handlers attached to it. Any ideas? It may not matter, but I'm using jQuery, Twitter-Bootstrap, and Ruby on Rails. Clues so far: When I remove

How to modify the ajax Post data in a beforeSend event?

妖精的绣舞 提交于 2019-12-05 22:40:49
Hello I have a form that submits remotely with the jQuery UJS for rails. I binded to the beforeSend event to allow me to modify the data submitting to the serve. It's not working. Here is what I have in the beforeSend: settings.data = JSON.stringify({ 'list_item[title]' : 'hi?? there' }) This doesn't work. In the server logs I see this: Started POST "/lists/9/list_items" for 127.0.0.1 at 2011-10-24 14:04:36 -0700 Processing by ListItemsController#create as JSON Parameters: {"{\"list_item"=>{"title"=>{"\":\"hi?? there\"}"=>nil}}, "list_id"=>"9"} Any idea what I'm doing wrong? I want to

Rails: cannot submit a remote form that was loaded via Ajax

元气小坏坏 提交于 2019-12-05 05:52:28
Goal I have a page with a list of items, coming from a Rails backend. I want to be able to edit a row in that list, using Ajax calls via Rails UJS. Approach I've added an edit button to the end of each row. The edit button is a link_to ... :remote => true . Clicking it loads the list again, but with the selected row in edit mode. The editable row is embedded in a form ... :remote => true . The save button in that row is a submit button. index.html.haml #editor %table - @items.each do |item| %tr = render :partial => 'row', :locals => { :item => item } _row.html.haml ... %td // a number of

Rails 3 - Periodic Refresh of DIV

流过昼夜 提交于 2019-12-04 20:31:32
I am trying to refresh the contents of a div using AJAX/Unobtrusive JavaScript/JQuery. This is easy to do if I make a "refresh" link and give it a data-remote attribute. However, I would like to refresh every 2 seconds using the setInterval function rather than using a link. This code should demonstrate what I'm trying to do. It does not work when put in application.js because the ERB is not evaluated, but hopefully it will explain my goal. setInterval(function(){ $("#scuttlebutt").html("<%= escape_javascript(render 'scuttlebutt') %>"); },2000); What would be a proper way to do this in Rails 3

Use JS to change <form> from remote to non-remote in Rails 3, HAML

陌路散爱 提交于 2019-12-04 17:39:45
问题 The problem is that i have a remote form that, based on condition, id like to convert to a non-remote form (using UJS), and then submit. note the form has a file upload. Here's the details: I have initially rendered the remote form using = form_for @myobj, :url => {:action=>"remoteAction", :controller=>"myobjects"}, :remote => true do |f| ... (f.fields....) which produces the HTML: <form id="new_myobj" class="new_myobj" method="post" accept-charset="UTF-8" data-remote="true" action="

Rails 3 UJS driver events

爷,独闯天下 提交于 2019-12-04 14:43:05
问题 According to Simone Carletti blog post, Rails 3 ajax helpers have changed a lot. We are supposed to write more javascript with rails 3 than we used to with rails 2. I tried to figure out how to show up an ajax loading gif -while an ajax query is running- in the "rails 3 way". I came up with this kind of code, which uses javascript events sent by the Rails 3 UJS driver. This example uses prototype: <div id="wait" style="display:none"> <img src="/images/ajax-loader.gif"> Please wait... </div>

How do I stop a remote form from submitting?

寵の児 提交于 2019-12-04 13:45:50
问题 I have a form that can be used both remotely and normally. = form_for @comment, html: { class: 'comment-form' }, remote: request.xhr? do |f| = f.text_area :body = f.submit I want the form to submit only if the body textarea has content: $(document).on 'submit', '.comment-form', (e) -> text = $(this).find('#comment_body').val() false if text.length < 1 That code works when the form is not Ajax. But when it's remote, it fails and the form still submits. Why? I also tried: if text.length < 1 e