Skip to content

Commit

Permalink
Merge pull request #638 from werpu/3.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
volosied authored Nov 21, 2023
2 parents f30ba62 + c984754 commit 06a5232
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,16 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr
//we simulate the dom level 2 form element here
var _newCls = null;
var bufInstance = null;
var _Lang = this;
if (!this.FormDataDecoratorArray) {
this.FormDataDecoratorArray = function (theFormData) {
this._valBuf = theFormData;
this._idx = {};
var _t = this;
_Lang.arrForEach(theFormData, function(item) {
var key = item[0];
_t._idx[decodeURIComponent(key)] = true;
});
};
_newCls = this.FormDataDecoratorArray;
_newCls.prototype.append = function (key, val) {
Expand All @@ -583,6 +589,12 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr
this._preprocessedData = theFormData;
this._valBuf = [];
this._idx = {};
var _t = this;
var keyValuePairs = theFormData.split(/\&/gi);
_Lang.arrForEach(keyValuePairs, function(item) {
var key = _Lang.trim(item.split(/\=/gi)[0]);
_t._idx[decodeURIComponent(key)] = true;
});
};
_newCls = this.FormDataDecoratorString;
_newCls.prototype.append = function (key, val) {
Expand All @@ -591,7 +603,8 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr
};
//for now we check only for keys which are added subsequently otherwise we do not perform any checks
_newCls.prototype.hasKey = function (key) {
return !!this._idx[key];
var _t = this;
return !!(this._idx[key]);
};
_newCls.prototype.makeFinal = function () {
if (this._preprocessedData != "") {
Expand All @@ -602,17 +615,23 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr
};
}
if (!this.FormDataDecoratorOther) {
/**
* expected a form data object
* @param theFormData object of type form data or something similar
* @constructor
*/
this.FormDataDecoratorOther = function (theFormData) {
this._valBuf = theFormData || [];
this._valBuf = theFormData;
this._idx = {};

};
_newCls = this.FormDataDecoratorOther;
_newCls.prototype.append = function (key, val) {
this._valBuf.push([encodeURIComponent(key), encodeURIComponent(val)]);
this._idx[key] = true;
};
_newCls.prototype.hasKey = function (key) {
return !!this._idx[key];
return !!(this._idx[key] || this._valBuf.has(key));
};
_newCls.prototype.makeFinal = function () {
return this._valBuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,24 @@ _MF_SINGLTN(_PFX_XHR+"_AjaxUtils", _MF_OBJECT,
*/
appendIssuingItem: function (item, targetBuf) {
// if triggered by a Button send it along
if (item && item.type &&
(item.type.toLowerCase() == "submit" ||
item.type.toLowerCase() == "button" )) {
//buttons not always have a name unlike inputs
targetBuf.append(item.id || item.name, item.value);
var identifier = item.id || item.name;
var type = ((item && item.type) || "").toLowerCase();

if(targetBuf.hasKey(identifier)) { //already processed within the values
return;
}

//MYFACES-4606 we cannot send a value on an unchecked box as issuing element
var isCheckboxRadio = "checkbox" == type || "radio" == type;
if(isCheckboxRadio && !item.checked) {
return;
} else if (isCheckboxRadio) {
var value = ("undefined" == typeof item.value || null == item.value) ? true : item.value;
targetBuf.append(identifier, value);
//item must have a valid value to be able to be appended, without it no dice!
} else if(!(("undefined" == typeof item.value) || (null == item.value))) {
var itemValue = item.value;
targetBuf.append(identifier, itemValue);
}
},

Expand Down

0 comments on commit 06a5232

Please sign in to comment.