Commit 722a71e5 authored by Jos Schellevis's avatar Jos Schellevis

extra validation on form processing

parent 6878d936
...@@ -8,38 +8,42 @@ function getFormData(parent) { ...@@ -8,38 +8,42 @@ function getFormData(parent) {
data = {}; data = {};
$( "#"+parent+" input,#"+parent+" select" ).each(function( index ) { $( "#"+parent+" input,#"+parent+" select" ).each(function( index ) {
node = data ; if ($(this).attr('id') == undefined) {
keyparts = $(this).attr('id').split('.'); // we need an id.
for (var i in keyparts) { return;
if (!(keyparts[i] in node)) { }
node[keyparts[i]] = {}; node = data ;
} keyparts = $(this).attr('id').split('.');
if (i < keyparts.length - 1 ) { for (var i in keyparts) {
node = node[keyparts[i]]; if (!(keyparts[i] in node)) {
} else { node[keyparts[i]] = {};
if ($(this).is("select")) { }
// selectbox, collect selected items if (i < keyparts.length - 1 ) {
var tmp_str = ""; node = node[keyparts[i]];
$(this).children().each(function(index){ } else {
if ($(this).prop("selected")){ if ($(this).is("select")) {
if (tmp_str != "") tmp_str = tmp_str + ","; // selectbox, collect selected items
tmp_str = tmp_str + $(this).val(); var tmp_str = "";
} $(this).children().each(function(index){
node[keyparts[i]] = tmp_str; if ($(this).prop("selected")){
}); if (tmp_str != "") tmp_str = tmp_str + ",";
} else if ($(this).prop("type") == "checkbox") { tmp_str = tmp_str + $(this).val();
// checkbox input type
if ($(this).prop("checked")) {
node[keyparts[i]] = 1 ;
} else {
node[keyparts[i]] = 0 ;
} }
node[keyparts[i]] = tmp_str;
});
} else if ($(this).prop("type") == "checkbox") {
// checkbox input type
if ($(this).prop("checked")) {
node[keyparts[i]] = 1 ;
} else { } else {
// regular input type node[keyparts[i]] = 0 ;
node[keyparts[i]] = $(this).val();
} }
} else {
// regular input type
node[keyparts[i]] = $(this).val();
} }
} }
}
}); });
return data; return data;
...@@ -59,6 +63,10 @@ function getFormData(parent) { ...@@ -59,6 +63,10 @@ function getFormData(parent) {
*/ */
function setFormData(parent,data) { function setFormData(parent,data) {
$( "#"+parent+" input,#"+parent+" select" ).each(function( index ) { $( "#"+parent+" input,#"+parent+" select" ).each(function( index ) {
if ($(this).attr('id') == undefined) {
// we need an id.
return;
}
node = data ; node = data ;
keyparts = $(this).attr('id').split('.'); keyparts = $(this).attr('id').split('.');
for (var i in keyparts) { for (var i in keyparts) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment