unobtrusive-javascript

Rails :confirm modifier callback?

我是研究僧i 提交于 2019-12-04 10:29:56
问题 I want to call a javascript function that will be conditional upon a user's response to the confirm box. For example, I have the following anchor: <%= link_to 'Sign Out', destroy_session_path, confirm: 'Are you sure that you would like to sign out?', method: :delete %> Should I just abandon the unobtrusive javascript and bind my own jQuery callback to my anchor? Or is there some magical way to pass a callback function to the Rails url helper? I did not see any discussion of callbacks in the

Asp MVC unobtrusive Client Validation always returning true

Deadly 提交于 2019-12-04 07:16:17
We have a partial view that contains a form with unobtrusive client validation enabled. If we load the partial view using Html.Action, the validation works on the client side. If when the user clicks a link we use JQuery to populate a div with the partial view , the client validation always returns true. Any idea what is going on? You need to parse the new html to hook up the validation controls. You can do this using: $.validator.unobtrusive.parse( $('.selector' ) ); where the selector returns the container holding the new HTML. This is what I use with tabbed interfaces. 来源: https:/

file input MVC 3 Client-side validation for required

你离开我真会死。 提交于 2019-12-04 05:44:36
Simple question... Is it possible to use client side MVC 3 validation on inputs of type file? To explain: MVC 3 uses its model validation with IClientValidatable and unobtrusive javascript to allow you to write validation on the server side and have it render the client side using jquery validate using Microsoft's plugins. To make a property required you add the attribute below [Required] public HttpPostedFileBase CvFile {get; set;} As long as client side val and unobtrusive javascript is on in the config this should all fire on the client. However HttpPostedFileBase (i.e. <input type="file"

jQuery unobtrusive validation in .NET MVC 3 - showing success checkmark

让人想犯罪 __ 提交于 2019-12-04 03:10:58
Using jQuery unobtrusive validation within a .NET MVC project and that seems to be working fine. I'm now trying to show a green checkmark when the field validates correctly (client-side and/or remote). Here's a sample field declaration: <div class="clearfix"> @Html.LabelFor(model => model.Address1, "Street") <div class="input"> @Html.TextBoxFor(model => model.Address1, new { @class = "xlarge", @maxlength = "100", @placeholder = "e.g. 123 Main St" }) <span class="help-message"> @Html.ValidationMessageFor(model => model.Address1) <span class="isaok">Looks great.</span> </span> <span class="help

When should I use call() vs invoking the function directly?

半腔热情 提交于 2019-12-03 23:57:17
I've got a JavaScript application that uses a lot of callbacks. A typical function will take a callback, and wrap it with another callback. Namespace.foo = function( arg, their_on_success ) { var my_on_success = function( result ) { console.log( 'my_on_success() called' ); if( 'function' === typeof their_on_success ) { their_on_success( result ); } } something( arg, my_on_success ); }; Given the above example, when should such a setup us the native call() method (passing the result var as the second argument) rather than invoking their_on_success() and passing in the result via function

I am not able to understand how jQuery chaining works [closed]

妖精的绣舞 提交于 2019-12-03 22:45:59
I am not able to understand how jQuery chaining works. jQuery("div").attr("id", "_id") .hide() .show(); I did something like chaining, but I'm not sure if it's the same logic that jQuery uses. var fun = (function (parma) { return function () { return { start: function () { console.log("start"); return this; }, mid: function () { console.log("mid"); return this; }, last: function () { console.log("last"); return this; } } } })(); // Working fun().start() .mid() .last(); If the return value of a function is an object that has a method, you can call that method immediately. Simple as that. Since

MVC Twitter Bootstrap unobtrusive error handling

牧云@^-^@ 提交于 2019-12-03 18:20:49
问题 I've been trying to get MVC Jquery unobtrusive error handling working with twitter bootstrap for some time now. Its got to the point were i'm either going to edit jquery.validate or do some hack and slash on document.ready. In order to get unobtrusive error handling to work with Bootstrap and MVC I need to make it so the 'error' class it appended to the 'control-group' class. As well as that, the 'error' class is appended to the input. I was wondering if anyone in the community has already

MVC3 DataAnnotationsExtensions error using numeric attribute

蓝咒 提交于 2019-12-03 17:24:13
I've installed Scott's Kirkland DataAnnotationsExtensions. In my model I have: [Numeric] public double expectedcost { get; set; } And in my View: @Html.EditorFor(model => model.expectedcost) Now, when the page tries to render I get the following error: Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: number Any ideas why I'm getting the error ? The quick answer is simply remove the attribute [Numeric] The longer explanation is that by design, validation already adds a data-val-number because it's of type double

Rails 3: How do I call a javascript function from a js.erb file

 ̄綄美尐妖づ 提交于 2019-12-03 16:22:02
Now that I've upgraded to Rails 3, I'm trying to figure out the proper way to separate and reuse pieces of javascript. Here's the scenario I'm dealing with: I have a page with two areas: one with elements that should be draggable, the other with droppables. When the page loads I use jQuery to setup the draggables and droppables. Currently I have the script in the head portion of application.html.erb, which I'm sure is not the right solution but at least works. When I press a button on the page, an ajax call is made to my controller that replaces the draggables with a new set of elements that

Do you plan for javascript being off?

旧巷老猫 提交于 2019-12-03 15:48:41
I'm coding a fairly large and complex site by myself, so do you think I need to support javascript being turned off? Its a lot of extra work supporting full page postbacks for stuff I could quickly do with JSON and ajax. You need to write server-side code in any case to handle the posts, whether they are from AJAX or not. So why not code according to the DRY principle , and reuse the same logic for standard postbacks and AJAX requests? I think you should support that. In fact, if your site involves SEO and bot indexing your site and all that, you SHOULD support javascript off. As a modern web