mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-25 09:13:11 -05:00
convert to auto form
This commit is contained in:
@@ -86,6 +86,25 @@
|
|||||||
validate-on="input"
|
validate-on="input"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- Number Input -->
|
||||||
|
<v-number-input
|
||||||
|
v-else-if="inputField.type === fieldTypes.NUMBER"
|
||||||
|
v-model="model[inputField.varName]"
|
||||||
|
variant="underlined"
|
||||||
|
:control-variant="inputField.numberInputConfig?.controlVariant"
|
||||||
|
density="comfortable"
|
||||||
|
:label="inputField.label"
|
||||||
|
:name="inputField.varName"
|
||||||
|
:min="inputField.numberInputConfig?.min"
|
||||||
|
:max="inputField.numberInputConfig?.max"
|
||||||
|
:precision="inputField.numberInputConfig?.precision"
|
||||||
|
:hint="inputField.hint"
|
||||||
|
:hide-details="!inputField.hint"
|
||||||
|
:persistent-hint="!!inputField.hint"
|
||||||
|
:rules="!(inputField.disableUpdate && updateMode) ? inputField.rules || [] : []"
|
||||||
|
validate-on="input"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Option Select -->
|
<!-- Option Select -->
|
||||||
<v-select
|
<v-select
|
||||||
v-else-if="inputField.type === fieldTypes.SELECT"
|
v-else-if="inputField.type === fieldTypes.SELECT"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export const fieldTypes = {
|
export const fieldTypes = {
|
||||||
TEXT: "text",
|
TEXT: "text",
|
||||||
TEXT_AREA: "textarea",
|
TEXT_AREA: "textarea",
|
||||||
|
NUMBER: "number",
|
||||||
SELECT: "select",
|
SELECT: "select",
|
||||||
BOOLEAN: "boolean",
|
BOOLEAN: "boolean",
|
||||||
PASSWORD: "password",
|
PASSWORD: "password",
|
||||||
|
|||||||
@@ -218,6 +218,16 @@ const tableHeaders: TableHeaders[] = [
|
|||||||
show: true,
|
show: true,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-quantity"),
|
||||||
|
value: "standardQuantity",
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit"),
|
||||||
|
value: "standardUnit",
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: i18n.t("general.date-added"),
|
text: i18n.t("general.date-added"),
|
||||||
value: "createdAt",
|
value: "createdAt",
|
||||||
@@ -230,7 +240,12 @@ const { store: unitStore, actions: unitActions } = useUnitStore();
|
|||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Form items (shared)
|
// Form items (shared)
|
||||||
const formItems: AutoFormItems = [
|
type StandardizedUnitTypeOption = {
|
||||||
|
text: string;
|
||||||
|
value: StandardizedUnitType;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formItems = computed<AutoFormItems>(() => [
|
||||||
{
|
{
|
||||||
label: i18n.t("general.name"),
|
label: i18n.t("general.name"),
|
||||||
varName: "name",
|
varName: "name",
|
||||||
@@ -267,7 +282,57 @@ const formItems: AutoFormItems = [
|
|||||||
varName: "fraction",
|
varName: "fraction",
|
||||||
type: fieldTypes.BOOLEAN,
|
type: fieldTypes.BOOLEAN,
|
||||||
},
|
},
|
||||||
];
|
{
|
||||||
|
label: i18n.t("data-pages.units.standard-quantity"),
|
||||||
|
varName: "standardQuantity",
|
||||||
|
type: fieldTypes.NUMBER,
|
||||||
|
numberInputConfig: {
|
||||||
|
min: 0,
|
||||||
|
max: undefined,
|
||||||
|
precision: undefined,
|
||||||
|
controlVariant: "hidden",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: i18n.t("data-pages.units.standard-unit"),
|
||||||
|
varName: "standardUnit",
|
||||||
|
type: fieldTypes.SELECT,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.fluid-ounce"),
|
||||||
|
value: "fluid_ounce",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.cup"),
|
||||||
|
value: "cup",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.ounce"),
|
||||||
|
value: "ounce",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.pound"),
|
||||||
|
value: "pound",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.milliliter"),
|
||||||
|
value: "milliliter",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.liter"),
|
||||||
|
value: "liter",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.gram"),
|
||||||
|
value: "gram",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: i18n.t("data-pages.units.standard-unit-labels.kilogram"),
|
||||||
|
value: "kilogram",
|
||||||
|
},
|
||||||
|
] as StandardizedUnitTypeOption[],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Create
|
// Create
|
||||||
|
|||||||
@@ -1,11 +1,28 @@
|
|||||||
import type { VForm as VuetifyForm } from "vuetify/components/VForm";
|
import type { VForm as VuetifyForm } from "vuetify/components/VForm";
|
||||||
|
|
||||||
type FormFieldType = "text" | "textarea" | "list" | "select" | "object" | "boolean" | "color" | "password";
|
type FormFieldType
|
||||||
|
= | "text"
|
||||||
|
| "textarea"
|
||||||
|
| "number"
|
||||||
|
| "list"
|
||||||
|
| "select"
|
||||||
|
| "object"
|
||||||
|
| "boolean"
|
||||||
|
| "color"
|
||||||
|
| "password";
|
||||||
|
|
||||||
export type FormValidationRule = (value: any) => boolean | string;
|
export type FormValidationRule = (value: any) => boolean | string;
|
||||||
|
|
||||||
export interface FormSelectOption {
|
export interface FormSelectOption {
|
||||||
text: string;
|
text: string;
|
||||||
|
value?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FormFieldNumberInputConfig {
|
||||||
|
min?: number;
|
||||||
|
max?: number;
|
||||||
|
precision?: number;
|
||||||
|
controlVariant?: "split" | "default" | "hidden" | "stacked";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FormField {
|
export interface FormField {
|
||||||
@@ -18,8 +35,9 @@ export interface FormField {
|
|||||||
rules?: FormValidationRule[];
|
rules?: FormValidationRule[];
|
||||||
disableUpdate?: boolean;
|
disableUpdate?: boolean;
|
||||||
disableCreate?: boolean;
|
disableCreate?: boolean;
|
||||||
|
numberInputConfig?: FormFieldNumberInputConfig;
|
||||||
options?: FormSelectOption[];
|
options?: FormSelectOption[];
|
||||||
selectReturnValue?: string;
|
selectReturnValue?: "text" | "value";
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AutoFormItems = FormField[];
|
export type AutoFormItems = FormField[];
|
||||||
|
|||||||
Reference in New Issue
Block a user