unobtrusive-javascript

jquery validate not loaded requirejs

烂漫一生 提交于 2019-12-13 16:26:24
问题 I have a main module in RequireJS: require([ 'jquery', 'jquery.validate', 'jquery.validate.unobtrusive' ], function ($) { $(document).ready(function () { var validator = $("form").validate(); if ($("#txtFirstName").val() !== "") validator.element("#txtFirstName"); }); }); When I load this page, I get a JavaScript error: TypeError: $(...).validate is not a function var validator = $("form").validate();** I don't now why? All scripts are loaded: 回答1: You'll need to configure shim to "wire" the

Event binding on dynamically created elements?

末鹿安然 提交于 2019-12-13 07:00:12
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off . This happens on page ready and works just fine. The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound. I have found this plugin (jQuery Live

dynamic content in ajax while rendering partial views

心不动则不痛 提交于 2019-12-13 00:44:26
问题 How do I get dynamic content when user clicks on different links? views/dashboard/index.html.haml .container - @trips.each do |trip| = link_to trip.id, quick_view_trips_path, remote: true I'm pretty sure the quick_view_trips_path is incorrect as all the links are this: <a href="/trips/quick_view">1</a> <a href="/trips/quick_view">13</a> <a href="/trips/quick_view">51</a> Somehow I need to make these links dynamic, and then when user clicks on it, the modal window would be dynamic too. If I

Which is faster, .on() or .click()?

谁都会走 提交于 2019-12-12 09:47:52
问题 If I have a table with links to delete a record, which is the best way to wire up the click event? Do these evaluate the same under the hood? $("#table").on("click", ".delete", function(){ //do stuff }); or $("#table .delete").click(function(){ //do stuff }); 回答1: No, they don't. In the way you are using them... .on() The way you are using it (delegation) , will save you cycles at attachment as well as memory, because it doesn't actually attach the events in that moment, as it provides a

Remote validation causes submit inputs (multiple-submit-buttons) to be null

白昼怎懂夜的黑 提交于 2019-12-12 05:19:09
问题 I recently implemented remote validation in my form: ViewModel: [Remote("IsTagUnique", "myController", "myArea", ErrorMessage = "This tag already exists.")] public string tag { get; set; } Controller: public ActionResult IsTagUnique(string tag) { using (db) { try { var myTag = db.ASAuftraege.Single(m => m.tag == tag); return Json(false, JsonRequestBehavior.AllowGet); } } catch (Exception) { return Json(true, JsonRequestBehavior.AllowGet); } } } [HttpPost] [ValidateAntiForgeryToken] public

Jquery retrieve values of Dynamically created elements

一曲冷凌霜 提交于 2019-12-12 04:25:11
问题 I have a html page with a form. The form has Div which gets populated dynamically with Input elements like text box,radio,checkbox etc. Now I want to retrieve the values of these dynamically created elements in the Html page,so that i can submit it to a page. //HTML PAGE <script type="text/javascript"> $(function() { populateQuestions(); }); $("#submit_btn").click(function() { // validate and process form here //HOW TO ??retrieve values??? var optionSelected = $("input#OptionSelected_1").val(

Unobtrusive Javascript-Basic Implementation: How do I bind all elements of a particular class to a function in Javascript?

天大地大妈咪最大 提交于 2019-12-12 03:32:19
问题 So I was reading this SO question earlier, and I am currently trying to get a basic implementation of Unobtrusive javascript working, but I don't know where I'm struggling. Normally this is something I would struggle with for much longer until I figure it out on my own, but I'm starting to get in a bit of a time crunch... I have a several elements within my HTML document with a class called "RMButton", and I'm trying to make all of my elements with this class call a function called

Graceful degradation with Dijit

大兔子大兔子 提交于 2019-12-12 02:38:38
问题 I've been a dojo (core) user for a few years now. Building my own widgets atop the dojo space; neglecting dijit and dojox. Working in my own world. That had it's advantages, but I kept having the feeling that I'm reinventing the wheel while building yet another tabbed panel, carousel or dialog box. So I've decided to use dijit. With my own widgets, I've set some basic rules : A widget must degrade gracefully [when no js is loaded] for accessibility and SEO There should be no redraws after the

Event binding on dynamically created elements?

给你一囗甜甜゛ 提交于 2019-12-12 01:25:06
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off . This happens on page ready and works just fine. The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound. I have found this plugin (jQuery Live

Need MVC 3 Grid with AJAX paging/sorting with unobtrusive javascript

夙愿已清 提交于 2019-12-11 20:39:43
问题 I'm fairly new to MVC 3 and and looking for a grid component that allows sorting and paging, but will also use progressive enhancement so provide fully AJAX based sorting and paging. Ideally I'd like the generated markup to be very clean and customizable with minimal JS embedded on the page 回答1: Get a look at http://datatables.net/ There are various nuget packages and codeplex projects developped to easilyintegrate these with asp.net mvc such as this one: http://datatablesmvc.codeplex.com/ 来源