Major overhaul to the theme and now functioning.
This commit is contained in:
+155
@@ -0,0 +1,155 @@
|
||||
import {
|
||||
useProxiedModel
|
||||
} from "./chunk-KA77II4V.js";
|
||||
import {
|
||||
consoleWarn,
|
||||
propsFactory
|
||||
} from "./chunk-LZ5T2ERG.js";
|
||||
import {
|
||||
computed,
|
||||
inject,
|
||||
markRaw,
|
||||
provide,
|
||||
ref,
|
||||
shallowRef,
|
||||
toRef,
|
||||
watch
|
||||
} from "./chunk-2MKFL3BX.js";
|
||||
|
||||
// node_modules/vuetify/lib/composables/form.js
|
||||
var FormKey = /* @__PURE__ */ Symbol.for("vuetify:form");
|
||||
var makeFormProps = propsFactory({
|
||||
disabled: Boolean,
|
||||
fastFail: Boolean,
|
||||
readonly: Boolean,
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
default: null
|
||||
},
|
||||
validateOn: {
|
||||
type: String,
|
||||
default: "input"
|
||||
}
|
||||
}, "form");
|
||||
function createForm(props) {
|
||||
const model = useProxiedModel(props, "modelValue");
|
||||
const isDisabled = toRef(() => props.disabled);
|
||||
const isReadonly = toRef(() => props.readonly);
|
||||
const isValidating = shallowRef(false);
|
||||
const items = ref([]);
|
||||
const errors = ref([]);
|
||||
async function validate() {
|
||||
const results = [];
|
||||
let valid = true;
|
||||
errors.value = [];
|
||||
isValidating.value = true;
|
||||
for (const item of items.value) {
|
||||
const itemErrorMessages = await item.validate();
|
||||
if (itemErrorMessages.length > 0) {
|
||||
valid = false;
|
||||
results.push({
|
||||
id: item.id,
|
||||
errorMessages: itemErrorMessages
|
||||
});
|
||||
}
|
||||
if (!valid && props.fastFail) break;
|
||||
}
|
||||
errors.value = results;
|
||||
isValidating.value = false;
|
||||
return {
|
||||
valid,
|
||||
errors: errors.value
|
||||
};
|
||||
}
|
||||
function reset() {
|
||||
items.value.forEach((item) => item.reset());
|
||||
}
|
||||
function resetValidation() {
|
||||
items.value.forEach((item) => item.resetValidation());
|
||||
}
|
||||
watch(items, () => {
|
||||
let valid = 0;
|
||||
let invalid = 0;
|
||||
const results = [];
|
||||
for (const item of items.value) {
|
||||
if (item.isValid === false) {
|
||||
invalid++;
|
||||
results.push({
|
||||
id: item.id,
|
||||
errorMessages: item.errorMessages
|
||||
});
|
||||
} else if (item.isValid === true) valid++;
|
||||
}
|
||||
errors.value = results;
|
||||
model.value = invalid > 0 ? false : valid === items.value.length ? true : null;
|
||||
}, {
|
||||
deep: true,
|
||||
flush: "post"
|
||||
});
|
||||
provide(FormKey, {
|
||||
register: (_ref) => {
|
||||
let {
|
||||
id,
|
||||
vm,
|
||||
validate: validate2,
|
||||
reset: reset2,
|
||||
resetValidation: resetValidation2
|
||||
} = _ref;
|
||||
if (items.value.some((item) => item.id === id)) {
|
||||
consoleWarn(`Duplicate input name "${id}"`);
|
||||
}
|
||||
items.value.push({
|
||||
id,
|
||||
validate: validate2,
|
||||
reset: reset2,
|
||||
resetValidation: resetValidation2,
|
||||
vm: markRaw(vm),
|
||||
isValid: null,
|
||||
errorMessages: []
|
||||
});
|
||||
},
|
||||
unregister: (id) => {
|
||||
items.value = items.value.filter((item) => {
|
||||
return item.id !== id;
|
||||
});
|
||||
},
|
||||
update: (id, isValid, errorMessages) => {
|
||||
const found = items.value.find((item) => item.id === id);
|
||||
if (!found) return;
|
||||
found.isValid = isValid;
|
||||
found.errorMessages = errorMessages;
|
||||
},
|
||||
isDisabled,
|
||||
isReadonly,
|
||||
isValidating,
|
||||
isValid: model,
|
||||
items,
|
||||
validateOn: toRef(() => props.validateOn)
|
||||
});
|
||||
return {
|
||||
errors,
|
||||
isDisabled,
|
||||
isReadonly,
|
||||
isValidating,
|
||||
isValid: model,
|
||||
items,
|
||||
validate,
|
||||
reset,
|
||||
resetValidation
|
||||
};
|
||||
}
|
||||
function useForm(props) {
|
||||
const form = inject(FormKey, null);
|
||||
return {
|
||||
...form,
|
||||
isReadonly: computed(() => !!(props?.readonly ?? form?.isReadonly.value)),
|
||||
isDisabled: computed(() => !!(props?.disabled ?? form?.isDisabled.value))
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
makeFormProps,
|
||||
createForm,
|
||||
useForm
|
||||
};
|
||||
//# sourceMappingURL=chunk-GAYXO4FM.js.map
|
||||
Reference in New Issue
Block a user