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

fix(Calendar): replace invalid date with a valid one in event #7701

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

KumJungMin
Copy link
Contributor

Defect Fixes


How To Resolve

  • When typing a date that exceeds the allowed yearRange, the input field adjusts it to a valid date.
  • However, the onChange event still passes the unadjusted invalid date.
  • The validateDate function ensures the date is valid.
  • Therefore, I called the validateDate function in the updateValueOnInput callback.
 const updateValueOnInput = (event, rawValue, invalidCallback) => {
      try {
          const value = parseValueFromString(props.timeOnly ? rawValue.replace('_', '') : rawValue);

          if (isValidSelection(value)) {
              validateDate(value);  // this!
              updateModel(event, value);
              const date = value.length ? value[0] : value;
              updateViewDate(event, date);
              ...
}

Test

sample code
import { Calendar } from '@/components/lib/calendar/Calendar';
import { useState } from 'react';

export function BasicDoc() {
  const [date, setDate] = useState(null);

  return (
      <div className="card">
          <Calendar showButtonBar monthNavigator yearNavigator value={date} onChange={(e) => setDate(e.value)} yearRange="2020:2030" showIcon showOnFocus={false} />
          <p>CUR DATE: {date?.toLocaleDateString()}</p>
      </div>
  );
}

before: When typing an invalid date(01/01/2000), the onChange event passes the unadjusted date value.

2025-02-14.10.13.57.mov

after: When typing an invalid date(01/01/2000), the onChange event now passes the adjusted valid date value(01/01/2020).

2025-02-14.10.13.26.mov

@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Feb 14, 2025
@melloware melloware merged commit 351ca26 into primefaces:master Feb 14, 2025
3 checks passed
@melloware
Copy link
Member

Thanks @KumJungMin !

@KumJungMin KumJungMin deleted the fix/issue-7691 branch February 14, 2025 13:37
Copy link

vercel bot commented Feb 14, 2025

Deployment failed with the following error:

Creating the Deployment Timed Out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calendar: Actual value is not being limited by yearRange when manually typing
2 participants