Skip to content

Commit

Permalink
Added placeholder option to FormInput when type is select so that it …
Browse files Browse the repository at this point in the history
…autogenerates a default undefined option with the placeholder.
  • Loading branch information
rizen committed May 31, 2024
1 parent baeff80 commit 9b056aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions components/ving/FormInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<MarkdownInput v-else-if="type == 'markdown' && (isString(val) || isNull(val) || isUndefined(val))"
v-model="val" :placeholder="placeholder" :id="computedId" @change="emit('change')"
/>
<Dropdown v-else-if="type == 'select'"
v-model="val" :name="name" :id="computedId" :options="options" :class="fieldClass" :required="required"
<Dropdown v-else-if="type == 'select'" :placeholder="placeholder"
v-model="val" :name="name" :id="computedId" :options="modifiedOptions" :class="fieldClass" :required="required"
@change="emit('change')" optionLabel="label" optionValue="value" />
<InputText
v-else-if="['text', 'email'].includes(type) && (isString(val) || isNull(val) || isUndefined(val))"
Expand Down Expand Up @@ -99,6 +99,16 @@ const invalidForm = inject('invalidForm', (a) => { });
const empty = computed(() => isNil(props.modelValue));
const modifiedOptions = computed(() => {
if ( props.placeholder ) {
return [
{ value: undefined, label : props.placeholder },
...props.options,
]
}
return props.options;
});
const invalid = computed(() => {
if (props.required && empty.value) {
subtext.value = `${displayName} is required.`;
Expand Down
1 change: 1 addition & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ outline: deep
### 2024-05-31
* Don't do an update if no data has changed when the user calls update().
* Fix enum2labels problem when options list is undefined.
* Added placeholder option to FormInput when type is select so that it autogenerates a default undefined option with the placeholder.

### 2024-05-30
* Fixed and if-else-if bug in FormInput component that was causing fields to be displayed twice if it was an int.
Expand Down

0 comments on commit 9b056aa

Please sign in to comment.