anutron/more-behaviors — Issue #3: Delegator.SubmitLink.js question regarding injectValues
Author: Rolf-nl
Created: 2012-01-14 22:25:48+00:00
State: open

if typeOf(value) is not an array, shouldn't the created input element also be added to the injected array for destroying after submit? At the moment you only push in the ones if value is type array.

var createInput = function(name, value){
return new Element('input', {
type: 'hidden',
name: name,
value: value
});
}

var injectValues = function(form, data){
var injected = new Elements();
Object.each(data, function(value, key){
if (typeOf(value) == 'array'){
value.each(function(val){
injected.push(
createInput(key, val)
);
});
} else {
injected.push(
createInput(key, value)
);
}
});
form.adopt(injected);
return injected;
};

Additional:
When typeOf(value) == array, shouldn't you check if key has [] at the end of the name? Not sure if the delegator should provide this extra check if user makes a mistake supplying an incorrect key/value when value is array, key is not correct and you end up with array.length inputs but only the last one is used in the backend..

Addition 2:
Should I have forked & edited it + send a pull request instead?