Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Monday, 2 February 2015

MVC / Jquery unobtrusive validation

http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-1

Also for how do attach a new client side method to unobtrusive validation e.g.

jQuery.validator.unobtrusive.adapters.add(adapterName, [params], fn);

see this article...

http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html

 

Note: For any element a in your <form>, you can do this to figure out what validation is attached to the containing <form> for that element...


$.data(a.form, "validator").settings.rules

e.g.

$.data(a.form, "validator").settings.rules.MiddleInitial
Object {maxlength: "1", __dummy__: true}

$.data(a.form, "validator").settings.messages.MiddleInitial
Object {maxlength: "The middle initial must be a single charater"}

Tuesday, 8 July 2014

Kendo DropDownList popup keep open alternative code using list property

Should you ever have the need to keep a kendo drop down list open using typescript, then the following example is how you should go about it with the latest kendo libraries that we're referencing

Note: The benefits of doing it this way is that you can strongly type all the typescript code, instead of relying on an undocumented extension property called popup off the drop down list control.

Typescript code:

export class AssignmentDashboard extends Base.HomePageBase {

private filterEventsDdLInitialized = false;

public filterEventsDdlInitialize: () => void = () => {

if (this.filterEventsDdLInitialized === false) {

var filterEventsDdl: kendo.ui.DropDownList = $("#viewEventListFilters").data("kendoDropDownList");

if (!this.isDefined(filterEventsDdl)) {

alert('viewEventListFilters drop down list widget not found');

return;

}

filterEventsDdl.list.on("mousedown", "*", (e: JQueryEventObject) => {

this.lastTarget = <HTMLElement>e.currentTarget;

});

filterEventsDdl.bind("close", (e: kendo.ui.DropDownListCloseEvent) => {

if ($.contains(e.sender.list[0], this.lastTarget)) {

e.preventDefault();

}

this.lastTarget = document.body;

//e.preventDefault(); // comment out for prod. use this to lock ddl during debugging/editing.

});

filterEventsDdl.list.on("click", "input", this.filterOptionChangeHandler);

this.filterEventsDdLInitialized = true;

}

}

CSHTML code:

attach the filterEventsDdlInitialize class method to the e.open event of the drop down in the cshtml… e.g.

.Events(e =>

{

e.Open("$(document).data('assignmentDashboardContext').filterEventsDdlInitialize");

})

e.g.

@(Html.Kendo().DropDownList()

.Name("viewEventListFilters")

.HtmlAttributes(new { style = "width: 240px;" })

.Height(410)

.BindTo(Model.FilterOptionsBinder)

.Text("Events")

.Value("Events")

.Events(e =>

{

e.Open("$(document).data('assignmentDashboardContext').filterEventsDdlInitialize");

})

.Template(tempHolder)

)

Wednesday, 21 May 2014

BrowserLink and other new VS 2013 features

Perhaps the most significant enhancement to creating web applications in Visual Studio for many years. Check out how you can edit your pages in line in the browser, and it updates the source code back in visual studio directly, using the new BrowserLink feature...

http://www.asp.net/visual-studio/overview/2013/visual-studio-2013-web-editor-features-browser-link

More features worth a look are all listed under the parent page here...

http://www.asp.net/visual-studio/overview/2013

Wednesday, 11 December 2013

Altering the HTTP response using Fiddler

Should you ever have the need to change the http response to a web server, then please note in the latest version of Fiddler it's actually possible to do this without having to hack the CustomRules.js file that the Fiddler training videos and documentation tell you about.

You can simply set up an AutoResponder tab rule as follows

1. Stick a file in %userprofile%\Documents\Fiddler2\Captures\Responses folder

2. Highlight the request you want to set up a rule for

3. Got to the AutoResponder tab and check Enable automatic responses and unmagtched requests passthrough

4. Click Add rule

5. In the dropdown list control at the bottom, select the file that you dropped in the folder in step 1 above.

6. Hit the save button

7. Clear the Cache

clip_image001

Now next time you request that resource, the version you have saved on disk will be downloaded instead. You can check this by looking in the IE cache folder %userprofile

%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files

More detail about request and response breakpoints in fiddler here… (this is very useful should you wish to change the request going to the server in the first place as well)…

http://www.youtube.com/watch?v=8bo5kXMAcV0&list=PLvmaC-XMqeBbw72l2G7FG7CntDTErjbHc&index=2

P.S. For more powerful / permanent debugging solution you can just alter the fiddler customrules.js as follows

static function OnBeforeResponse(oSession: Session) {

        if (m_Hide304s && oSession.responseCode == 304) {

            oSession["ui-hide"] = "true";

        }

if (oSession.uriContains("Name=ViewerScript")) {

                                                oSession["x-replywithfile"]="Reserved.ReportViewerWebControl.axd";

                                }

    }

Wednesday, 18 September 2013

Preload Images with CSS, Javascript or Ajax

See here for many ways to achieve this...

http://perishablepress.com/3-ways-preload-images-css-javascript-ajax/

Personally I'm sticking with the following...

http://jsfiddle.net/chafferm/VU2dq/

Note the type check for array in this example is probably overkill, as it is for all browser versions, we could have used jQuery isArray instead, or even Array.isArray in ECMA script 5 (IE 9 or higher).

Saturday, 24 August 2013

Plunkr Noughts And Crosses Game

Spent some time with my new favourite javascript online editor of the moment http://plunkr.co. I've found I can use my tablet, an iPad and even a smart phone to edit my HTML using this editor, although most of the time it's done using Google Chrome on a laptop.

My daughter and I find this game is best played with two wireless mouse devices plugged into the laptop, and you take it in turns to move the pieces into the squares.

P.S. Some hidden gems in Plunkr are the keyboard shortcuts:

Ctrl+S = Save
Ctrl+Up/ Ctrl+Down = Cycle through files
Ctrl+Enter = Preview / Run your code

To run the game, click here:
http://run.plnkr.co/plunks/kLcfW2/

To edit the code, feel free at this link:

http://plnkr.co/edit/kLcfW2?p=preview

Plunkr - Noughts and Crosses Game

Thursday, 17 January 2013

Project Silk for all your HTML web application needs

A colleague of mine pointed out this white paper article that Microsoft have kindly put together, which appears to be a full overview on how to construct a web site in this day an age.

"Guidance for building cross-browser web applications with a focus on client-side interactivity. These applications take advantage of the latest web standards like HTML5, CSS3 and ECMAScript 5 along with modern web technologies such as jQuery, Internet Explorer 9, and ASP.NET MVC3"

http://silk.codeplex.com/

You can also download it all in pdf format from the following link

http://www.microsoft.com/en-us/download/details.aspx?id=27290

Monday, 22 October 2012

YSlow CSS inspector

Just installed the YSlow browser extension for Chrome (although versions are available for other browsers too!).

http://developer.yahoo.com/yslow/

Not bad for finding where things on your site can be improved…

image

image

Wednesday, 26 September 2012

JavaScript dates are zero based for month part

It appears that JS treats dates as zero indexed on the month part when you construct them in the format new Date("yyyy", "MM", "dd")

clip_image001

Wednesday, 18 July 2012

Client side tools for Phone development

These are the client side tools that have just been mentioned for developing responsive web applications for mobile platform today on http://live.aspconf.net/ 

image

Frameworks to learn for SPAs

If you're thinking of building single page applications in future, then you will need to learn the following frameworks for sure..

image

Monday, 9 July 2012

Knockout.js learning

I've come across this great site for helping you to get to grips with the basics of creating some excellent user interfaces in javascript and HTML5.

http://learn.knockoutjs.com/

image

If anything, it's great just for using the editor for quick checking of HTML in a preview mode using the Run functionality on the left hand side...

image

Tuesday, 29 May 2012

JQuery event debugging

http://james.padolsey.com/javascript/debug-jquery-events-with-listhandlers/

CODE

Here’s a useful debugging plugin for jQuery. It will list the handler/’s of any event bound to any element:

/ UPDATED -> NOW WORKS WITH jQuery 1.3.1
$.fn.listHandlers = function(events, outputFunction) {
return this.each(function(i){
var elem = this,
dEvents = $(this).data('events');
if (!dEvents) {return;}
$.each(dEvents, function(name, handler){
if((new RegExp('^(' + (events === '*' ? '.+' : events.replace(',','|').replace(/^on/i,'')) + ')$' ,'i')).test(name)) {
$.each(handler, function(i,handler){
outputFunction(elem, '\n' + i + ': [' + name + '] : ' + handler );
});
}
});
});
};

USAGE


It’s pretty simple to use, you can specify the elements (as you usually would, via a selector), the events to be listed and the output function to which the plugin will feed the data.

If you’re using firebug then it’s best to use either the console.log function or console.info.

// List all onclick handlers of all anchor elements:
$('a').listHandlers('onclick', console.info);   // List all handlers for all events of all elements:
$('*').listHandlers('*', console.info);   // Write a custom output function:
$('#whatever').listHandlers('click',function(element,data){
$('body').prepend('<br />' + element.nodeName + ': <br /><pre>' + data + '<\/pre>');
});

Note, this will only work if you’ve used jQuery’s native event registration methods, e.g.$(elem).click() / $(elem).bind('click').

image

Thursday, 8 December 2011

MVC tutorials

A good set of MVC tutorials up here by pluralsight

http://www.asp.net/mvc/pluralsight

Also, during the JavaScript and Ajax demo, the lecturer points out this excellent link for speeding up your web sites

http://developer.yahoo.com/performance/rules.html

image

You can also then use this add on in Firefox to run those rules and evaluate your site

https://addons.mozilla.org/en-US/firefox/addon/yslow/

For JQuery samples and demos have a look at this link

http://jqueryui.com/

How to find the last interactive logons in Windows using PowerShell

Use the following powershell script to find the last users to login to a box since a given date, in this case the 21st April 2022 at 12pm un...