Geek Building The Bridge Part 2 / 804 posts / 1,947 comments / feed / comments feed

AdvAjax, multiple submit button

A fellow in team complained about the bug existing within the current framework. A form with multiple submit button was not submitted correctly. All submit button was submitted instead of just the one clicked. A glimpse look over advajax.js, there’re no support for this. Before I made the patch read upon W3C specification to check whether multiple submit button in one form is indeed valid. And it does. Well, using Behaviour with attribute selector rule, I made a simple helper script to disable all submit button except the one clicked. And then the rest are handled by advajax. it works as expected in W3C’s form submission spec, ie: only successful controls can be submitted. Below is the behaviour rule. I’m sorry, there’s no love for you non Behaviour user. But I can guarantee that you’ll find no issue porting this code to your need.



/*
AdvAjax helper to solve problem with multiple submit button. This rule will disable all submit button except one clicked
*/

var advajax_helper = {
'input[type="submit"]‘: function (element) {
element.onclick = function() {
/*console.log(this);*/
this.disableAllButThis(this);
};
element.disableAllButThis = function(obj) {
var the_exception_obj = obj;
while(obj.parentNode) {
/*console.log(’Lookign for pNode’, obj.parentNode.tagName);*/
if (obj.parentNode.tagName == ‘FORM’) {
var frm = obj.parentNode;
var elmnts = frm.getElementsByTagName(’input’);
for(var i=0;i /*console.log(elmnts[i]);*/
if (elmnts[i].type=="submit") {
if ((elmnts[i].name==the_exception_obj.name) && (elmnts[i].value==the_exception_obj.value))
continue;
else {
/*elmnts[i].style.border = "2px solid red";*/
elmnts[i].disabled=true;
}
}
}

/* done */
break;
} else {
/* go up */
obj = obj.parentNode;
}
}
};
}
}

Behaviour.register(advajax_helper);

Sphere: Related Content

No comments

Leave a comment

« Back to text comment