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

isBefore and isAfter config values should contain itself when comparing #1

Closed
Asim-Tahir opened this issue Jun 2, 2022 · 2 comments

Comments

@Asim-Tahir
Copy link

Asim-Tahir commented Jun 2, 2022

Problem πŸ˜΅β€πŸ’«

import JustValidatePluginDate from "just-validate-plugin-date";

validation.addField("input[type=date][name=start_date]", [
  {
    plugin: JustValidatePluginDate(() => ({
      format: "yyyy-mm-dd",
      isBefore: "2022-06-08", // or new Date(2022, 5, 8)
      isAfter: "2022-06-02" // or new Date(2022, 5, 2)
    })),
    errorMessage: "Date should be between 2022-06-02 and 2022-06-08",
  },
]);

Validation fails when input[type="date"][name="start_date"] value is 2022-06-08. Likewise, when the input value is set to 2022-06-02 validation fails. Both exclude itself when compared to the input value.

Expectation πŸ’­

When the input value is equal to isBefore or isAfter should validate with no fails.

Temporary Solution 🀞🏻

Add one day to isBefore and subtract one day to isAfter.

import JustValidatePluginDate from "just-validate-plugin-date";

const isBefore = new Date(2022, 5, 8);
isBefore.setDate(isBefore.getDate() + 1);
const isAfter = new Date(2022, 5, 2);
isAfter.setDate(isAfter.getDate() - 1);

validation.addField("input[type=date][name=start_date]", [
  {
    plugin: JustValidatePluginDate(() => ({
      format: "yyyy-mm-dd",
      isBefore,
      isAfter
    })),
    errorMessage: "Date should be between 2022-06-02 and 2022-06-08",
  },
]);
github-actions bot pushed a commit that referenced this issue Jun 15, 2022
# [1.2.0](v1.1.1...v1.2.0) (2022-06-15)

### Features

* [#1](#1) add isEqual, isBeforeOrEqual, isAfterOrEqual validators ([22706d6](22706d6))
@horprogs
Copy link
Owner

Thanks for the reporting.

I decided to keep the isAfter and isBefore as it is, but I added the new validators: isBeforeOrEqual, isAfterOrEqual and just in case if needed to compare just for the same day: isEqual

Released 1.2.0 version

@Asim-Tahir
Copy link
Author

Thx, I will try it ASAP.

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

No branches or pull requests

2 participants