UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

31 lines (30 loc) 1.68 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */ const minMaxStepTypes = ["date", "datetime-local", "month", "number", "range", "time", "week"]; const patternTypes = ["email", "password", "search", "tel", "text", "url"]; const minMaxLengthTypes = ["email", "password", "search", "tel", "text", "textarea", "url"]; function updateConstraintValidation(inputComponent, input, propName, matchesType) { const attributeName = propName.toLowerCase(); const value = inputComponent[propName]; if (matchesType && value != null) { input.setAttribute(attributeName, `${value}`); } else { input.removeAttribute(attributeName); } } function syncHiddenFormInput(type, inputComponent, hiddenFormInput) { hiddenFormInput.type = type === "textarea" ? "text" : type; const isMinMaxStepType = minMaxStepTypes.includes(type); const numericInputComponent = inputComponent; updateConstraintValidation(numericInputComponent, hiddenFormInput, "min", isMinMaxStepType); updateConstraintValidation(numericInputComponent, hiddenFormInput, "max", isMinMaxStepType); updateConstraintValidation(numericInputComponent, hiddenFormInput, "step", isMinMaxStepType); const isMinMaxLengthType = minMaxLengthTypes.includes(type); const textualInputComponent = inputComponent; updateConstraintValidation(textualInputComponent, hiddenFormInput, "minLength", isMinMaxLengthType); updateConstraintValidation(textualInputComponent, hiddenFormInput, "maxLength", isMinMaxLengthType); const isPatternType = patternTypes.includes(type); updateConstraintValidation(textualInputComponent, hiddenFormInput, "pattern", isPatternType); } export { syncHiddenFormInput as s };