epicmaxco / vuestic-ui

Free and Open Source UI Library for Vue 3 🤘
https://vuestic.dev
MIT License
3.34k stars 324 forks source link

Let VaDateInput accept a null value #4169

Closed Bond-Addict closed 3 weeks ago

Bond-Addict commented 3 months ago

Allow a user to have a null date input. Dev's will have to handle validation as they normal would with other controls.

Description

Currently you have to provide a date input regardless of whether or not you have any rules. This just allow a user to remove the date inputted and be able to pass the form validation.

const onInputTextChanged = ({ target }: Event) => {
  if (props.disabled) { return }

  const inputValue = (target as HTMLInputElement).value

  if (isValid.value) {
    valueComputed.value = inputValue === '' ? null : parseDateInputValue(inputValue)
  }
}

Types of changes

Bond-Addict commented 3 weeks ago

I'll need to dig a bit deeper in this issue. This solution makes it visible "Invalid Date" in text field. I'll need to find some references on what to do if there is invalid date. Also, model value should become not null, but props.clearValue.

We also need a story with tests for that.

export const NullValue = () => ({
  components: { VaDateInput },
  data () {
    return {
      value: null,
    }
  },
  template: `
  [[value]]: {{ value === null ? 'null' : value }}
  <VaDateInput v-model="value" clearable manual-input clear-value="null" />
  `,
})

If you use the story for manual input, if you click in and then click out or tab out, it no longer throws a validation error. If you do the same but on the story for validation, it will throw the validation error as expected.

Bond-Addict commented 3 weeks ago

https://github.com/epicmaxco/vuestic-ui/assets/117455332/9186fd20-1afa-49e6-bfe9-42b4d5732036

m0ksem commented 3 weeks ago

I added demo and fixed the validation issue...

Bond-Addict commented 3 weeks ago

Ah I see. When you said demo, you meant an actual story for storybook. My bad. As far as the validation error, what error was there? I hadn't noticed anything in my testing.