Skip to content
This repository has been archived by the owner on Nov 30, 2018. It is now read-only.

Commit

Permalink
Use error handler. Closes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jun 5, 2013
1 parent 71d293b commit 77fb823
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tmp/**
docs**
.idea
node_modules
testee.log
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ Append the dForm object to each selected element. If the element is of the same
a `type : 'form'` on a `<form>`) or if no type has been given run the subscribers and
add the attributes on the current element. Optionally use a converter with a given name.

**$(form).dform(url \[, success\])** *{String}* *{Function}*<br />
Load a JSON form definition using GET from a given URL and execute a success handler when it returns.
The handler gets the data passed and has `this` refer to the form element.
**$(form).dform(url \[, success\], \[, error\])** *{String}* *{Function}* *{Function}*<br />
Load a JSON form definition using GET from a given URL and execute a success handler when it returns
or an error handler if the request faiuls. The handler gets the data passed and has `this` refer to the form element.

**$(form).dform('run', options)** *{Object}*<br />
Run all subscribers from a given dForm object on the selected element(s).
Expand Down
20 changes: 10 additions & 10 deletions src/dform.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @param {Object} object The object to use
* @return {Array} An array containing all properties in the object
*/
keyset = function (object) {
keyset = function (object) {
return $.map(object, function (val, key) {
return key;
});
Expand All @@ -44,7 +44,7 @@
* @return {Object} A new object containing only the properties
* with names given in keys
*/
withKeys = function (object, keys) {
withKeys = function (object, keys) {
var result = {};
each(keys, function (index, value) {
if (object[value]) {
Expand Down Expand Up @@ -80,7 +80,7 @@
* @param {String} type The type of the current element as in the registered types
* @return {Object} The jQuery object
*/
runSubscription = function (name, options, type) {
runSubscription = function (name, options, type) {
if ($.dform.hasSubscription(name)) {
this.each(function () {
var element = $(this);
Expand All @@ -98,7 +98,7 @@
* @param {Object} options The options to use
* @return {Object} The jQuery element this function has been called on
*/
runAll = function (options) {
runAll = function (options) {
var type = options.type, self = this;
// Run preprocessing subscribers
this.dform('run', '[pre]', options, type);
Expand Down Expand Up @@ -278,18 +278,18 @@
*/
ajax : function (params, success, error) {
var options = {
success: function (data) {
self.dform(data);
if(success) {
success.call(self, data);
}
},
error : error,
url : params
}, self = this;
if (typeof params !== 'string') {
$.extend(options, params);
}
options.success = function (data) {
self.dform(data);
if(success) {
success.call(self, data);
}
}
$.ajax(options);
},
/**
Expand Down
5 changes: 4 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ $(document).ready(function () {
$('<div>').dform('test.json', function(data) {
equal(data.html, 'The test', 'Data passed to success callback');
equal(this.html(), 'The test', 'Form got created');
start();
$('<div>').dform('missing.json', function() {}, function() {
ok(true, 'Error handler called');
start();
});
});
})
});

0 comments on commit 77fb823

Please sign in to comment.