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

Let VaDateInput accept a null value #4169

Merged
merged 4 commits into from May 23, 2024

Conversation

Bond-Addict
Copy link
Contributor

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any feature but make things better)

…dation as they normal would with other controlls.
@m0ksem m0ksem self-requested a review March 1, 2024 20:13
Copy link
Contributor

@m0ksem m0ksem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" />
  `,
})

@Bond-Addict
Copy link
Contributor Author

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
Copy link
Contributor Author

Vuesticnullabledateinput.1.mp4

@Bond-Addict Bond-Addict requested a review from m0ksem May 23, 2024 17:55
@m0ksem
Copy link
Contributor

m0ksem commented May 23, 2024

I added demo and fixed the validation issue...

@m0ksem m0ksem merged commit fd9f342 into epicmaxco:develop May 23, 2024
1 check passed
@Bond-Addict
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants