Skip to content

Commit

Permalink
add to auto-form instead of having hidden fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cmintey committed Feb 24, 2023
1 parent 0c6ca8b commit 6b29fd6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
13 changes: 7 additions & 6 deletions frontend/components/global/AutoForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
:label="inputField.label"
:name="inputField.varName"
:hint="inputField.hint || ''"
:disabled="updateMode && inputField.disableUpdate"
:disabled="(inputField.disableUpdate && updateMode) || (!updateMode && inputField.disableCreate)"
@change="emitBlur"
/>

<!-- Text Field -->
<v-text-field
v-else-if="inputField.type === fieldTypes.TEXT || inputField.type === fieldTypes.PASSWORD"
v-model="value[inputField.varName]"
:readonly="inputField.disableUpdate && updateMode"
:disabled="inputField.disableUpdate && updateMode"
:readonly="(inputField.disableUpdate && updateMode) || (!updateMode && inputField.disableCreate)"
:disabled="(inputField.disableUpdate && updateMode) || (!updateMode && inputField.disableCreate)"
filled
:type="inputField.type === fieldTypes.PASSWORD ? 'password' : 'text'"
rounded
Expand All @@ -46,8 +46,8 @@
<v-textarea
v-else-if="inputField.type === fieldTypes.TEXT_AREA"
v-model="value[inputField.varName]"
:readonly="inputField.disableUpdate && updateMode"
:disabled="inputField.disableUpdate && updateMode"
:readonly="(inputField.disableUpdate && updateMode) || (!updateMode && inputField.disableCreate)"
:disabled="(inputField.disableUpdate && updateMode) || (!updateMode && inputField.disableCreate)"
filled
rounded
class="rounded-lg"
Expand All @@ -66,7 +66,8 @@
<v-select
v-else-if="inputField.type === fieldTypes.SELECT"
v-model="value[inputField.varName]"
:readonly="inputField.disableUpdate && updateMode"
:readonly="(inputField.disableUpdate && updateMode) || (!updateMode && inputField.disableCreate)"
:disabled="(inputField.disableUpdate && updateMode) || (!updateMode && inputField.disableCreate)"
filled
rounded
class="rounded-lg"
Expand Down
8 changes: 3 additions & 5 deletions frontend/composables/use-users/user-form.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fieldTypes } from "../forms";
import { AutoFormItems } from "~/types/auto-forms";

export const useUserForm = (updateMode = false) => {
export const useUserForm = () => {
const userForm: AutoFormItems = [
{
section: "User Details",
Expand Down Expand Up @@ -34,6 +34,7 @@ export const useUserForm = (updateMode = false) => {
varName: "authMethod",
type: fieldTypes.SELECT,
hint: "This specifies how a user will authenticate with Mealie. If you're not sure, choose 'Mealie'",
disableCreate: true,
options: [{ text: "Mealie" }, { text: "LDAP" }],
},
{
Expand Down Expand Up @@ -69,10 +70,7 @@ export const useUserForm = (updateMode = false) => {
},
];

// fields that are hidden on creation, but shown on update
const hiddenOnCreate = ["authMethod"];

return {
userForm: userForm.filter((field) => updateMode || !hiddenOnCreate.includes(field.varName)),
userForm,
};
};
2 changes: 1 addition & 1 deletion frontend/pages/admin/manage/users/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { UserOut } from "~/lib/api/types/user";
export default defineComponent({
layout: "admin",
setup() {
const { userForm } = useUserForm(true);
const { userForm } = useUserForm();
const { groups } = useGroups();
const route = useRoute();
Expand Down
5 changes: 3 additions & 2 deletions frontend/types/auto-forms.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type FormFieldType = "text" | "textarea" | "list" | "select" | "object" | "boolean" | "color" | "password";

export interface FormSelectOption {
text: string;
description?: string;
text: string;
description?: string;
}

export interface FormField {
Expand All @@ -14,6 +14,7 @@ export interface FormField {
type: FormFieldType;
rules?: string[];
disableUpdate?: boolean;
disableCreate?: boolean;
options?: FormSelectOption[];
}

Expand Down

0 comments on commit 6b29fd6

Please sign in to comment.