From 5c3ab41cf39ec516d3d78352f32d6de5de5ea98c Mon Sep 17 00:00:00 2001 From: scottjehl Date: Sun, 19 Sep 2010 18:12:36 -0400 Subject: [PATCH] adding autoform plugin --- js/jQuery.mobile.forms.autoform.js | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 js/jQuery.mobile.forms.autoform.js diff --git a/js/jQuery.mobile.forms.autoform.js b/js/jQuery.mobile.forms.autoform.js new file mode 100644 index 00000000..5dcc3d36 --- /dev/null +++ b/js/jQuery.mobile.forms.autoform.js @@ -0,0 +1,57 @@ +/* +* jQuery Mobile Framework : "autoform" plugin +* Copyright (c) jQuery Project +* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. +* Note: Code is in draft form and is subject to change +*/ +(function($){ + +//ajax response callbacks +$.formhandlers = { + 'default' : function(data,type){ + return $(data).find('.ui-content:eq(0)'); + } +}; + +$.fn.autoform = function(options){ + return $(this).each(function(){ + $this = $(this); + + //extendable options + var o = $.extend({ + submitEvents: 'change', + method: $this.attr('method'), + action: $this.attr('action'), + injectResponse: true,//should be data-attr driven + dataFilter: $.formhandlers['default'], //should be data-attr driven + theme: 'b' + }, options); + + $this.addClass('ui-autoform ui-body ui-bar-'+o.theme); + + $this.bind(o.submitEvents, function(){ + $(this).submit(); + }); + + $this.submit(function(){ + $.pageLoading(); + $.ajax({ + url: o.action, + type: o.method, + data: $(this).serialize(), + dataFilter: o.dataFilter, + success: function(data,textStatus){ + $('.ui-page-active .ui-content').html( $('
').append(data).mobilize() ); + $.pageLoading(true); + } + }); + return false; + }); + }); +}; + + + + +})(jQuery); +