From 07ce511ae612d52652ef3ab2bf16062cdd5ef131 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 4 Feb 2024 21:02:27 +0100 Subject: [PATCH] Support JSON.stringify & Object.assign on FormData proxy --- src/htmx.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/htmx.js b/src/htmx.js index 1e09da10..5f7ebdc8 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -3112,6 +3112,10 @@ var htmx = (function() { // Forward symbol calls to the FormData itself directly return Reflect.get(...arguments) } + if (name === 'toJSON') { + // Support JSON.stringify call on proxy + return () => Object.fromEntries(formData) + } if (name in target) { // Wrap in function with apply to correctly bind the FormData context, as a direct call would result in an illegal invocation error if (typeof target[name] === 'function') { @@ -3144,6 +3148,13 @@ var htmx = (function() { deleteProperty: function(target, name) { target.delete(name) return true + }, + // Support Object.assign call from proxy + ownKeys: function(target) { + return Reflect.ownKeys(Object.fromEntries(target)) + }, + getOwnPropertyDescriptor: function(target, prop) { + return Reflect.getOwnPropertyDescriptor(Object.fromEntries(target), prop) } }) }