Geeks With Blogs

News Infragistics JQuery Advertisement
----------------
profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers

Check out Elapser from T3rse!
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
And then listen to Francis Chan speaking at LifeLight in SD.
Programming and Learning from SD JavaScript
Uncaught SyntaxError: Unexpected token u. file JavaScript Error in MVC
I was getting a JavaScript error that pointed to line number 1 of my MVC page. I have a form on the page and expected the Unobtrusive Validation to work with the Data Annotations. It took me a while to realize the validation messages weren't showing. After I while I found that I was missing the @Html.ValidationMessageFor(m => m.Name). Adding that for each field fixed it. My password reset with token example. I was missing line 12 and 17. 1: @using (Html.BeginForm("PasswordRe... "Home")) 2: { ......

Posted On Monday, May 20, 2013 1:45 PM

Include your JavaScript references in the correct order
I was stuck for 2 hours on this. I was using Wijmo library and was including the complete library before the open js file. I kept getting’Uncaught TypeError: Cannot call method 'formatString' of undefined’. Finally, I switched the order and put the open js file before the complete js file and the error went away. The lesson is that undefined means you haven’t defined it yet . Make sure it isn’t defined below it and that you didn’t forget to include it ......

Posted On Monday, January 7, 2013 3:51 PM

jQuery 1.9.1+ Ajax Post is Failing even though it has a 200 Status
I’m using my DataService and AjaxService for JavaScript and upgraded to jQuery 1.9.1. One of my post methods, which was working before, started hitting the deferred fail, instead of the deferred’s done, even though the status code was 200. This method is not returning any JSON to the caller. The 1.9 upgrade guide states “Prior to 1.9, an ajax call that expected a return data type of JSON or JSONP would consider a return value of an empty string to be a success case, but return a null to the success ......

Posted On Wednesday, May 8, 2013 9:41 AM

MVC Validation of a Password with a Regular Expression
I have requirement (specification) that the password has to be at least 7 characters long and contain a special character (~@#$&*()-_+=) which are all the specials in the number keyboard row. I found that using the RegularExpression DataAnnotations is really slick, but there was a point that caught me for a while. The problem is that @".*([!@#$&*()-_+=]+).*$" works in the UI, but fails in the unit test. @"[!@#$&*()-_+=]+" works in the test, but not in the UI (the MVC unobtrusive library ......

Posted On Friday, April 26, 2013 11:16 AM

DataService and AjaxService for JavaScript
Here is what I’ve been using to make my JavaScript more modular and testable. I’m using JQuery’s promises and the Revealing Module Pattern. I got the idea for the DataServices from John Papa's Pluralsight course on Knockoutjs, but modified it to work with promises, instead of passing in the callback as a parameter. // DataService example: dataService.UiDataService = (function (ajaxService) { 'use strict'; var webServiceUrl = "/api/UiApi/", /** * @brief Get all the components from the service. */ ......

Posted On Friday, April 12, 2013 8:54 AM

Jasmine Specification Testing Pointers
I’ve been using Jasmine JavaScript testing library for Behavior Driven Development testing the last few months with KnockoutJs view models and the Revealing Module Pattern. We now have 244 specs on a system that will be around and hopefully expand. I was hired to get it going, then others will maintain it and add to it after I’m gone. They have helped me think through what needs to happen (when {X} it should do this), test functionality with out having to click through things and help stop me from ......

Posted On Friday, April 5, 2013 3:18 PM

Making jQuery UI Droppable Testable
I’m using jQuery UI’s droppable for drag and drop capabilities. I wanted to be able to test it with Jasmine, but I couldn’t find a way to mock it. I found Jasmine jQuery, but wasn’t able to figure out how to spyOn or mock $('#jQueryElement').droppab... accept: function (d) { return accept(d); }, drop: function (event, ui) { drop(event, ui); } }); So I created a wrapper for this function. I’ve found that creating wrappers is an easy way to make things testable and to remove coupling to libraries ......

Posted On Tuesday, March 26, 2013 9:47 AM

Use the bind method for Jasmine toThrow Tests
Thanks to Danyal Aytekin for his Stackoverflow answer. If you want to use the toThrow in Jasmin tests on actual functions, you can use the “Function.bind, which was introduced in JavaScript 1.8.5. This works in the latest versions of Chrome and Firefox, and you can patch other browsers by defining the function yourself.” From his answer:describe('using bind with jasmine', function() { var f = function(x) { if(x === 2) { throw new Error(); } } it('lets us avoid using an anonymous function', function() ......

Posted On Thursday, March 21, 2013 2:11 PM

JsonIgnore attribute in Json.Net to ignore properties
We’re using Entity Framework to query a complex object graph using the .Include(“”) method to eager load the results, then sending it to the client with the WebApi. We’ve overridden the JavaScript Serializer in the Application_Start of Global.asax.cs of our MVC application to avoid circular dependencies. These occurred because of the Code First classes that were generated from the EF Power Tools had references to each other. It also created really large JSON structures that we didn’t need all the ......

Posted On Tuesday, March 5, 2013 1:57 PM

Google map div id must be map_canvas
The examples from Google use <div id=”map_canvas”></div... for their element. I changed it to something more specific to my project, and the zoom controls started looking funny. I reverted and tried again with the same results. I finally came across this StackOverflow question and answer (thank you again StackOverflow!) and also added an answer to the bottom to clarify what I found. The lessons are: Make sure you use map_canvas. Make sure you don’t have a max-width on the image ......

Posted On Thursday, January 24, 2013 10:12 AM

Copyright © Aligned | Powered by: GeeksWithBlogs.net | Join free