Skip to content

@cmilfont /jsonForm.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
(function($){
var merge = function(merged, source){
for(var property in source) {
if( typeof source[property] === "object" &&
typeof merged[property] !== "undefined") {
merge(merged[property], source[property]);
} else {
merged[property] = source[property];
}
}
return merged;
};
var build = function(name, value){
return (function gerarJSON(json, name, value){
var hierarquia = name.split(".");
var propriedade = hierarquia.shift();
json[propriedade] = (hierarquia.length > 0)?
gerarJSON({}, hierarquia.join(".", value)):value;
return json;
})({}, name, value);
}
$.fn.extend({
getJSON: function(){
var json = {};
$(this).find("input,select,textarea")
.each(function(index, input){
var parcial = build( $(input).attr("name"), $(input).val());
merge(json, parcial);
});
return json;
}
});
})(jQuery);
$("form").getJSON()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.