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

In date picker, year accepts more than 4 digits #10675

Closed
1 task done
irfanalam opened this issue Mar 16, 2018 · 4 comments
Closed
1 task done

In date picker, year accepts more than 4 digits #10675

irfanalam opened this issue Mar 16, 2018 · 4 comments
Labels
component: date picker This is the name of the generic UI component, not the React module!

Comments

@irfanalam
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When you select the date and try to change year manually it should accept only 4 digits.

Current Behavior

When you select the date and try to change year manually it accepts more than 4 digits.

Steps to Reproduce (for bugs)

  1. select date
  2. change year manually
  3. try to input more than 4 digits

Context

Your Environment

Tech Version
Material-UI v1.0.0-beta.35
React 16.2.0
browser
etc
@mbrookes mbrookes added v0.x and removed v0.x labels Mar 16, 2018
@oliviertassinari
Copy link
Member

@irfanalam Are you referring to our native date-picker example in the documentation? I fear there is nothing we can do about it here. It could be an upstream limitation on the browser side. The community offers some alternative to the native date-picker.

@oliviertassinari oliviertassinari added component: date picker This is the name of the generic UI component, not the React module! external dependency Blocked by external dependency, we can’t do anything about it labels Mar 16, 2018
@MihailHaev
Copy link

@irfanalam Are you referring to our native date-picker example in the documentation? I fear there is nothing we can do about it here. It could be an upstream limitation on the browser side. The community offers some alternative to the native date-picker.

In native date-picker has attribute max or min, what can fix this problem, but it attributies doesn't apply to TextFiled

@danidanimoraes
Copy link

danidanimoraes commented Nov 19, 2020

Workaround: Limit dates with min-max:

<TextField
  InputProps={{inputProps: { min: "2020-05-01", max: "2020-05-04"} }}
  type="date"
 (...)
/>

In my case, I only used max: 31-12-9999

@oliviertassinari oliviertassinari removed the external dependency Blocked by external dependency, we can’t do anything about it label Nov 19, 2020
@Rits1501
Copy link

restrictYearInput(event: KeyboardEvent) {
const input = event.target as HTMLInputElement;
const maxLength = 4;
if (input.value.length >= maxLength && event.key >= '0' && event.key <= '9') {
event.preventDefault();
}
}
try this function it will work
mat-form-field appearance="outline">
Select DateTime
<input type="date" formControlName="fromDate" (change)="dateEvent($event)" [min]="minDate"
matInput placeholder="Select Booking Date" (keypress)="restrictYearInput($event)">
<mat-error *ngIf="formGroup.get('fromDate')?.hasError('required')">
From Date is required

<mat-error *ngIf="formGroup.get('fromDate')?.errors?.['invalidDate']">Invalid date
selection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: date picker This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

6 participants