forked from nilbus/unserialize-to-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQuery.unserializeForm.min.js
1 lines (1 loc) · 1.18 KB
/
jQuery.unserializeForm.min.js
1
(function(a){var b={_unserializeFormSetValue:function(b,c,d){if(a(b).length>1){a.each(b,function(b){if(a(this).attr("value")==c){a(this).attr("checked",true)}else{a(this).attr("checked",false)}})}else{if(a(b).attr("type")=="checkbox"){a(b).attr("checked",true)}else{if(d){a(b).val(c)}else{if(!a(b).val()){a(b).val(c)}}}}}};a.fn.unserializeForm=function(c,d){var e=a.extend({callback:undefined,"override-values":false},d);return this.each(function(){c=c.split("&");_callback=e["callback"];_override_values=e["override-values"];if(_callback&&typeof _callback!=="function"){_callback=undefined}var d=new Array;a.each(c,function(){var a=this.split("=");if(typeof a[0]!="undefined"&&typeof a[1]!="undefined"){d[a[0].replace(/\+/g," ")]=decodeURI(a[1].replace(/\+/g," "))}});c=d;a(this).find(":checked").attr("checked",false);for(var f in c){var g=a(this).add("input,select,textarea").find('[name="'+unescape(f)+'"]');var h=unescape(c[f]);if(_callback==undefined){b._unserializeFormSetValue(g,h,_override_values)}else{var i=_callback.call(this,unescape(f),h);if(i==false){var g=a(this).add("input,select,textarea").find('[name="'+unescape(f)+'"]');b._unserializeFormSetValue(g,h,_override_values)}}}})}})(jQuery)