Questions tagged [ujs]

UJS is an unobtrustive JavaScript adapter for jQuery, provided by the Ruby on Rails project. For questions about unobtrustive JavaScript in general, please see the [unobtrustive-javascript] tag.

UJS is an unobtrustive JavaScript adapter for jQuery, provided by the Ruby on Rails project.

Useful resources:

276 questions
46
votes
4 answers

Rails data-disable-with re-enabling button

I have a Rails Devise form that has javascript validation. When the user presses submit, the validation works and the user is refocused on the form where they need to be. However, rails uses the data-disable-with to disable the button after it has…
Ryan Murphy
  • 842
  • 1
  • 9
  • 20
37
votes
2 answers

Rails 3 remote form: How do I specify the content type?

I am using Rails 3.2, I have a form and I want it to be posted via ajax and have the controller return json. I am using a form_for helper like so: = form_for(@object, :remote => true, :format => :json) do |f| .... My objects controller create…
Chris
  • 6,076
  • 11
  • 48
  • 62
34
votes
11 answers

Rails 3 UJS - controller gets called twice by link_to :remote

I have a weird problem where JQuery is creating two AJAX requests for a link_to method. I am developing a Rails 3 app with JQuery for UJS. I have a toggle link which toggles between 'Follow' and 'Unfollow' My link is rendered as below:
chandru
  • 341
  • 1
  • 3
  • 3
31
votes
2 answers

How to render new.js.coffee.erb in app/views?

Using Rails 3.1 jquery_ujs, I have a link with :remote => true, and the controller new action responds with js and render new.js.erb which contains: $('#post-form').html('<%= escape_javascript(render(:partial => "form")) %>'); It renders the…
Raymond Law
  • 1,188
  • 1
  • 10
  • 14
19
votes
1 answer

Where are Rails 3 custom JavaScript events defined?

As I look through the Rails 3 jquery-ujs code, I notice that it binds to custom JavaScript events (submit.rails, click.rails, etc). Does anyone know where are these custom '.rails' events defined? I'm just trying to better understand how the UJS…
Bryan
  • 2,205
  • 1
  • 23
  • 43
19
votes
3 answers

With Rails UJS, how to submit a remote form from a function

I'm using Rails UJS. I have a form setup to do a remote submit like so:
I'm…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
17
votes
2 answers

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

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 =…
Sami Begg
  • 239
  • 2
  • 7
16
votes
5 answers

Rails 4: Disable submit button after click

I have a form_tag(foo_path(@foo), remote: true, id: 'foo-form' form and a submit button submit_tag ("Submit", :id => "foo-submit") I'd like to disable the submit button after it has been clicked. Obviously, I cannot use something like…
Tolsto
  • 1,418
  • 2
  • 17
  • 45
11
votes
3 answers

Simple example of Rails 3 + UJS using Ajax to make a remote call, and rendering the resulting JSON object

I'm trying to add some Ajax functionality in my Rails 3 app. Specifically, I want a button that will submit an Ajax request to call a remote function in my controller, which subsequently queries an API and returns a JSON object to the page. Once I…
Tony Stark
  • 24,588
  • 41
  • 96
  • 113
10
votes
1 answer

rails ujs - javascript not executing

This is a very strange problem. I've got a rails app in which I am replacing one partial on the page with another using UJS. Recently, it stopped worked, so I started logging throughout the process to see where it broke. Here's what I found: After…
Jeff Escalante
  • 3,137
  • 1
  • 21
  • 30
10
votes
3 answers

How to keep submit buttons disabled on remote forms until the next page has loaded

In my Rails 5.1 app using Turbolinks, I have added a data-disable-with attribute to my submit buttons, so that on click, the button will be disabled, to prevent accidentally submitting the data multiple times. This works great in many cases. The…
Patrick O'Grady
  • 548
  • 4
  • 13
10
votes
4 answers

Multipage vs Single Page and Unobtrusive Javascript

I have a section of a site with multiple categories of Widget. There is a menu with each category name. For anybody with Javascript enabled, clicking a category reveals the content of the category within the page. They can click between categories…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
8
votes
2 answers

Simple like/unlike button with rails 3, jquery, and ajax

I have a product, user, and like model. A user can like a product. I am trying to implement a simple like button which, upon a click, allows a user to like a product. Then the like button transforms into an unlike button, allowing the user to unlike…
deruse
  • 2,851
  • 7
  • 40
  • 60
8
votes
1 answer

Rails and data-disable-with not working with Safari

<%= f.button :button, 'Move', class: "btn btn-warning", data: { disable_with: " Moving…"} %> This works fine in Chrome but fails in Safari. This works on links but not on buttons or submits. There seems to be…
Dan Tappin
  • 2,692
  • 3
  • 37
  • 77
8
votes
5 answers

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

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…
Pascal Lindelauf
  • 4,782
  • 4
  • 40
  • 55
1
2 3
18 19