unobtrusive-javascript

Javascript not being rendered at script but as html instead

巧了我就是萌 提交于 2019-12-08 06:29:28
This question is to piggy back off of a previous one I asked yesterday , which deals with moving the create/edit feature of a model onto its index page. One last issue I am having is that I when I go to delete a model, I have some javascript that is supposed to run that reloads the list of models to reflect the change in the database. This js is being rendered as html. Here is the code that I think is relevant: in my controller: def destroy @post = Post.find(params[:id]) @post.destroy flash[:notice] = "Successfully destroyed post." @posts = Post.all respond_to do |format| format.js {render

can you use embedded ruby in custom javascript files in rails?

我的梦境 提交于 2019-12-08 04:55:24
问题 How does one embed ruby code in javascript for rails? I know you can do this easily in javascript responders for action methods (for e.g. in create.erb.js). But is there a way to do this for other custom javascript files that are included in the application using javascript_include_tag? For e.g. in create.erb.js I can write code such as <%= if current_user_name ="xyz" %> Is there a way to have this type of embedding in a custom js file such as custom.js that is used across the application and

Is it possible to “hack into” the unobtrusive validaton supported in ASP.NET MVC 3?

纵饮孤独 提交于 2019-12-07 15:20:08
问题 I want to be able to use the built-in, data-annotation based, client-side unobtrusive validation, but do my own ajax form submission after I know it passes. Something like this jQuery bit: $('#form').submit(function(e) { e.preventDefault(); if (PassesUnobtrusiveValidation()) { // ajax submit form } }); Is there a PassedValidation event, or something like it, (built into the default, asp.net mvc 3 data-annotation based client side validation) I can hook into (like the psuedocode in the example

jQuery how to trigger event after form post returns?

二次信任 提交于 2019-12-07 14:03:00
问题 I have an expensive form action that builds a zip file on the server and returns it to the browser. <form action='/download' method='post'> <input type='submit' value='download'/> </form> I want to block the page on click of the button so that the user doesn't repeatably hit the button. However I want to unblock the page after the form returns. How can trigger an event on successful completion of the form? (I know I can trigger this by changing the form to be an ajax submission but then the

Associating data to a DOM element for jQuery

て烟熏妆下的殇ゞ 提交于 2019-12-07 05:55:23
问题 In a previous life, I might have done something like this: <a href="#" onclick="f(311);return false;">Click</a><br/> <a href="#" onclick="f(412);return false;">Click</a><br/> <a href="#" onclick="f(583);return false;">Click</a><br/> <a href="#" onclick="f(624);return false;">Click</a><br/> Now with jQuery, I might do something like this: <a class="clicker" alt="311">Click</a><br/> <a class="clicker" alt="412">Click</a><br/> <a class="clicker" alt="583">Click</a><br/> <a class="clicker" alt=

Disable link with the prototype observe method

百般思念 提交于 2019-12-06 20:20:56
问题 I want to create a link like this: <a href="http://example.com">text</a> and replace the behavior so that the link downloads the content with Ajax instead when clicking. It is important for me not to replace the href attribute (so copying the link still works). One solution would be to do: $('link').onclick = function() { return false; }; but I would like to use the .observe method. But this doesn't work: $('link').observe('click', function() { return false; }); (which is quite logical). Any

Passing Javascript variables to Rails partials

帅比萌擦擦* 提交于 2019-12-06 13:44:35
问题 I am new in Rails and I am struggling on an apparently easy task. I have a (stripped down) form: <%= form_for @order, html: { :class => 'form-inline' } do |f| %> <fieldset> <legend><%= params[:action].capitalize %> Order</legend> <table class="table"> <thead> <tr> <th><%= f.label :symbol %></th> <th><%= f.label :price %></th> </tr> </thead> <tbody> <tr> <td><%= f.text_field :symbol, class: 'input-small' %></td> <td><%= f.text_field :price, class: 'input-small' %></td> </tr> </tbody> </table>

How to handle JavaScript events (e.g. 'link_to :remote') the Rails Way?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:36:52
问题 I am using Ruby on Rails 4 and I would like to handle JavaScript events the Rails way. That is, for example, given I have the following link_to('destroy', article_path(@article), :method => :delete, :remote => true) when I click on the above generated link then I would like the success JS event to update the page content by removing the deleted article DOM element. The AJAX response, whatever it is, should be ignored. I am aware of the existence of the rails.js file but I don't how to use it

Best practices for using AJAX without Rails' built-in helpers?

不羁岁月 提交于 2019-12-06 07:29:02
问题 In my blog application, some posts appear as excerpts -- i.e., the user sees the first (say) 500 characters, and can click a link to view the entire post. Here is the relevant partial: <% href = url_for post_path(:id => post) %> <h1 class="title"><%= post.title %></h1> <h2 class="published_on"><%= post.author %> wrote this <%= time_ago_in_words(post.published_on)%> ago</h2> <div class="body"> <% if defined?(length) %> <%= truncate_html(post.body, :length => length, :omission => "…<h1><a class

How important do you think Progressive Enhancement is? [closed]

泄露秘密 提交于 2019-12-06 04:55:19
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Progressive Enhancement is a web development methodology that not only allows greater portability and accessibility but in my opinion,