UNPKG

@scania/tegel

Version:
28 lines (27 loc) 1.15 kB
/** reference: https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/helpers.ts#L346 * * Appends a hidden input element to allow the component * work within and get picked up by a <form>. * @param element The element on which the input with be appended. * @param name Name of the input. * @param value The value of the input. * @param disabled Disables the input if true. * @param additionalAttributes Additional attributes that should be passed to the input. */ const appendHiddenInput = (element, name, value, disabled, additionalAttributes) => { let input = element.querySelector('input'); if (!element.querySelector('input')) { input = element.ownerDocument.createElement('input'); input.type = 'hidden'; if (additionalAttributes) { additionalAttributes.forEach((attr) => input === null || input === void 0 ? void 0 : input.setAttribute(attr.key, attr.value)); } element.appendChild(input); } if (input) { input.disabled = disabled; input.name = name || ''; input.value = value || ''; } }; export default appendHiddenInput;