Skip to content

Commit

Permalink
feat: allow empty select
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanvier committed Nov 4, 2024
1 parent b609dab commit 3a6e345
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/guide/inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
`FormSelect` extends `FormInput` props and adds the following options:
- `options` Key-value object for select options.
- `multiple` Boolean for multiple select.
- `empty` Boolean to allow empty value
- `empty` String with the empty label. Allows empty select

### Example
```VUE
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wgr-sa/nuxt-form",
"description": "Form builder for Nuxt",
"version": "0.9.1",
"version": "0.9.2",
"repository": "https://github.com/WGR-SA/nuxt-form.git",
"author": "jeanvier",
"license": "MIT",
Expand Down
10 changes: 8 additions & 2 deletions playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ import { max } from 'class-validator';
name="asdf"
:rules="[ 'isEmail']"
/> -->
<FormInput label='yo <a href="#">ok</a>' type="checkbox" name="tosnlpd" :rules="[{ equals: [true], message: 'coucou' }]" />
<FormInput name="yo" type="number" :rules="['isNotEmpty', {min: [1]}, {max: [25]}]" />
<FormSelect
name="yo"
:options="{ 'O': 'Oui', 'N': 'Non'}"
:rules="['isNotEmpty']"
empty="-- Select an option --"
/>
<!-- <FormInput label='yo <a href="#">ok</a>' type="checkbox" name="tosnlpd" :rules="[{ equals: [true], message: 'coucou' }]" />
<FormInput name="yo" type="number" :rules="['isNotEmpty', {min: [1]}, {max: [25]}]" /> -->
<!-- <FormTextarea name="saffs" :rules="['isNotEmpty']" /> -->
<!-- <FormRadio :options="{'O': 'Oui', 'N': 'Non'}" name="yo" laebl="Yo" />
<FormRadio :options="{'O': 'Oui', 'N': 'Non'}" name="yos" label="Yos" :rules="['isNotEmpty']" :empty="true" /> -->
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/FormSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const props = defineProps<{
disabled?: boolean,
value?: string,
placeholder?: string,
empty?: string,
}>()
const form = inject('form') as Form
Expand All @@ -28,6 +29,7 @@ const required = computed(() => props.required ?? false)
:disabled="disabled"
:multiple="multiple"
>
<option v-if="empty" disabled selected value="">{{ empty }}</option>
<option
v-for="(option, key) in options"
:key="key"
Expand Down

0 comments on commit 3a6e345

Please sign in to comment.