Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FormControl.vue #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/components/FormControl.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, ref, onMounted, onBeforeUnmount } from "vue";
import { computed, ref, onMounted, onBeforeUnmount, useAttrs } from "vue";
import { useMainStore } from "@/stores/main";
import FormControlIcon from "@/components/FormControlIcon.vue";

Expand Down Expand Up @@ -36,6 +36,14 @@ const props = defineProps({
type: Array,
default: null,
},
optionLabel: {
type: String,
default: 'label',
},
optionValue: {
type: String,
default: 'id',
},
type: {
type: String,
default: "text",
Expand All @@ -50,6 +58,8 @@ const props = defineProps({
ctrlKFocus: Boolean,
});

const attrs = useAttrs();

const emit = defineEmits(["update:modelValue", "setRef"]);

const computedValue = computed({
Expand Down Expand Up @@ -133,13 +143,14 @@ if (props.ctrlKFocus) {
v-model="computedValue"
:name="name"
:class="inputElClass"
v-bind="attrs"
>
<option
v-for="option in options"
:key="option.id ?? option"
:value="option"
:value="option[optionValue] ?? option"
>
{{ option.label ?? option }}
{{ option[optionLabel] ?? option }}
</option>
</select>
<textarea
Expand All @@ -151,6 +162,7 @@ if (props.ctrlKFocus) {
:maxlength="maxlength"
:placeholder="placeholder"
:required="required"
v-bind="attrs"
/>
<input
v-else
Expand All @@ -165,6 +177,7 @@ if (props.ctrlKFocus) {
:placeholder="placeholder"
:type="computedType"
:class="inputElClass"
v-bind="attrs"
/>
<FormControlIcon v-if="icon" :icon="icon" :h="controlIconH" />
</div>
Expand Down