Fix add remove button for multifield attributes

This commit is contained in:
Joseph Garrone 2024-06-02 00:31:08 +02:00
parent 6cdb83d730
commit 96a88fe865
2 changed files with 41 additions and 15 deletions

View File

@ -426,6 +426,7 @@ function AddRemoveButtonsMultiValuedAttribute(props: {
return ( return (
<> <>
{hasRemove && ( {hasRemove && (
<>
<button <button
id={`kc-remove${idPostfix}`} id={`kc-remove${idPostfix}`}
type="button" type="button"
@ -439,8 +440,9 @@ function AddRemoveButtonsMultiValuedAttribute(props: {
} }
> >
{msg("remove")} {msg("remove")}
{hasRemove ? <>&nbsp;|&nbsp;</> : null}
</button> </button>
{hasAdd ? <>&nbsp;|&nbsp;</> : null}
</>
)} )}
{hasAdd && ( {hasAdd && (
<button <button

View File

@ -0,0 +1,24 @@
import "minimal-polyfills/Object.fromEntries";
/**
* Functionally equivalent to structuredClone but
* functions are not cloned but kept as is.
* (as opposed to structuredClone that chokes if it encounters a function)
*/
export function structuredCloneButFunctions<T>(o: T): T {
if (!(o instanceof Object)) {
return o;
}
if (typeof o === "function") {
return o;
}
if (o instanceof Array) {
return o.map(structuredCloneButFunctions) as any;
}
return Object.fromEntries(
Object.entries(o).map(([key, value]) => [key, structuredCloneButFunctions(value)])
) as any;
}