diff --git a/readme.md b/readme.md index c7dbd5d..c548110 100644 --- a/readme.md +++ b/readme.md @@ -375,6 +375,14 @@ Generates: Address +**url** *{String|Object}*
+The `url` subscriber issues a `$(element).dform('ajax', options)` request to load content from remote files. + + { + "type" : "div", + "url": "form.json" + } + **type** *{String}*
Besides looking up the correct Type Generator it also adds a dform specific class to the element using `$.dform.options.prefix` (*ui-dform-* by default) and the type name. diff --git a/src/dform.core.js b/src/dform.core.js index 35fe916..4f788cb 100644 --- a/src/dform.core.js +++ b/src/dform.core.js @@ -195,10 +195,9 @@ * @param options * @param type */ - "url" : function (options, type) { - // TODO this.buildForm(options); + "url" : function (options) { + this.dform('ajax', options); }, - /** * Post processing function, that will run whenever all other subscribers are finished. * diff --git a/src/dform.js b/src/dform.js index 761e780..5d4d789 100644 --- a/src/dform.js +++ b/src/dform.js @@ -62,7 +62,7 @@ * @return {Object} A new object with all properties of the given object, except * for the ones given in the list of keys */ - withoutKeys = function (object, keys) { + withoutKeys = function (object, keys) { var result = {}; each(object, function (index, value) { if (!~$.inArray(index, keys)) { @@ -278,18 +278,19 @@ */ 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) { + var callback = success || params.success; + self.dform(data); + if(callback) { + callback.call(self, data); + } + } $.ajax(options); }, /** diff --git a/test/test.js b/test/test.js index 331aa75..5f993bb 100644 --- a/test/test.js +++ b/test/test.js @@ -56,7 +56,7 @@ $(document).ready(function () { equal(created.data('test'), 'Test data attribute', 'Added test data attribute'); }); - test("Ajax", 2, function() { + test("Ajax", 3, function() { stop(); $('
').dform('test.json', function(data) { equal(data.html, 'The test', 'Data passed to success callback'); diff --git a/test/test_subscribers.js b/test/test_subscribers.js index 5217e62..f91bafa 100644 --- a/test/test_subscribers.js +++ b/test/test_subscribers.js @@ -70,9 +70,9 @@ $(document).ready(function () { test("caption", function () { var simple = $('
').dform({ - type : 'text', - caption : 'The test' - }).find('label'), + type : 'text', + caption : 'The test' + }).find('label'), asElement = $('
').dform({ type : 'text', caption : { @@ -89,9 +89,9 @@ $(document).ready(function () { test("options", function () { var options = { - test1 : 'Test 1', - test2 : 'Test 2' - }, + test1 : 'Test 1', + test2 : 'Test 2' + }, select = $('