Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created January 30, 2013 05:29
Show Gist options
  • Save jmarnold/4670892 to your computer and use it in GitHub Desktop.
Save jmarnold/4670892 to your computer and use it in GitHub Desktop.
Conventional form activation
(function($, continuations) {
var activateFormsPolicy = {
matches: function(continuation) {
return continuation.isHtml() && continuation.options.activateForms;
},
execute: function (continuation) {
var element = continuation.options.element;
var content = $(continuation.response.responseText);
element.append(content);
element.activateValidation();
}
};
continuations.applyPolicy(activateFormsPolicy);
}(jQuery, jQuery.continuations));
// somewhere else...
$.ajax({
url: 'get/the/form',
type: 'GET',
acceptType: 'text/html',
options: {
element: $('#TheContainer'),
activateForms: true
}
});
// Note that the element pattern is particularly useful
// You could move the "append" action into a completely seperate policy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment