{"version":3,"file":"rockFormField.obs.js","sources":["../../../Framework/Controls/rockFormField.obs"],"sourcesContent":["<!-- Copyright by the Spark Development Network; Licensed under the Rock Community License -->\n<script lang=\"ts\">\n\n // NOTE: This file can be converted to final SFC form after upgrading Vue to\n // 3.3 so we can use the defineOptions() to disable inheritence.\n import { standardRockFormFieldProps } from \"@Obsidian/Utility/component\";\n import { useFormState } from \"@Obsidian/Utility/form\";\n import { newGuid } from \"@Obsidian/Utility/guid\";\n import { normalizeRules, validateValue } from \"@Obsidian/ValidationRules\";\n import { computed, defineComponent, onBeforeUnmount, ref, watch } from \"vue\";\n import RockLabel from \"./rockLabel.obs\";\n\n export default defineComponent({\n name: \"RockFormField\",\n\n inheritAttrs: false,\n\n components: {\n RockLabel\n },\n\n compilerOptions: {\n whitespace: \"preserve\"\n },\n\n props: {\n modelValue: {\n required: true\n },\n\n /**\n * If the modelValue is an object or array and its properties get changed, normally\n * that doesn't trigger a re-validation. If you enable this, it'll watch more deeply for\n * changes, therefore being able to trigger on any change to the modelValue. Only use\n * this when you actually need to because it can potentially cause performance issues\n * and unintended side effects.\n */\n watchDeep: {\n type: Boolean,\n default: false\n },\n\n name: {\n type: String,\n required: true\n },\n\n ...standardRockFormFieldProps\n },\n\n setup(props) {\n /** The reactive state of the form. */\n const formState = useFormState();\n\n /** The unique identifier used to identify this form field. */\n const uniqueId = `rock-${props.name}-${newGuid()}`;\n\n /** The internal value being tracked for the field. */\n const internalValue = ref<unknown>(\"\");\n\n /** The internal rules we will be used for calculations. */\n const internalRules = computed(() => normalizeRules(props.rules));\n\n /** Determines if this field is marked as required. */\n const isRequired = computed((): boolean => internalRules.value.includes(\"required\"));\n\n /** Holds the current error message for this form field. */\n const currentError = ref(\"\");\n\n /** Any error classes to be applied to the field depending on the current state. */\n const errorClasses = computed((): string[] => {\n if (!formState || formState.submitCount < 1) {\n return [];\n }\n\n return currentError.value !== \"\" ? [\"has-error\"] : [];\n });\n\n /** The text label to display to the user which identifies this field. */\n const fieldLabel = computed((): string => {\n return props.validationTitle || props.label;\n });\n\n // Watch for changes to the modelValue and update our internalValue.\n watch(() => [props.modelValue, props.rules], () => {\n internalValue.value = props.modelValue;\n\n const errors = validateValue(internalValue.value, props.rules);\n\n if (errors.length > 0) {\n currentError.value = errors[0];\n formState?.setError(uniqueId, fieldLabel.value, currentError.value);\n }\n else {\n currentError.value = \"\";\n formState?.setError(uniqueId, fieldLabel.value, \"\");\n }\n }, {\n immediate: true,\n deep: props.watchDeep\n });\n\n // If we are removed from the DOM completely, clear the error before we go.\n onBeforeUnmount(() => {\n currentError.value = \"\";\n formState?.setError(uniqueId, fieldLabel.value, \"\");\n });\n\n return {\n errorClasses,\n fieldLabel,\n formState,\n isRequired,\n uniqueId,\n };\n },\n\n template: `\n<slot name=\"pre\" />\n<div v-if=\"label || help || disableLabel\" class=\"form-group\" :class=\"[formGroupClasses, isRequired && !isRequiredIndicatorHidden ? 'required' : '', errorClasses]\">\n <RockLabel :for=\"uniqueId\" :help=\"help\" v-if=\"!disableLabel\">\n {{label}} <slot name=\"besideLabel\" />\n </RockLabel>\n <slot v-bind=\"{field: $attrs, uniqueId, fieldLabel}\" />\n</div>\n<slot v-else v-bind=\"{field: $attrs, uniqueId, fieldLabel}\" />\n<slot name=\"post\" />\n`\n });\n</script>\n"],"names":["defineComponent","name","inheritAttrs","components","RockLabel","compilerOptions","whitespace","props","_objectSpread","modelValue","required","watchDeep","type","Boolean","default","String","standardRockFormFieldProps","setup","formState","useFormState","uniqueId","concat","newGuid","internalValue","ref","internalRules","computed","normalizeRules","rules","isRequired","value","includes","currentError","errorClasses","submitCount","fieldLabel","validationTitle","label","watch","errors","validateValue","length","setError","immediate","deep","onBeforeUnmount","template"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYI,sCAAeA,eAAe,CAAC;MAC3BC,EAAAA,IAAI,EAAE,eAAe;MAErBC,EAAAA,YA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