angular / angular/components

feat(MatDatePicker): adding ability to use flexable format

Aperta
#27,859 2 commenti 1 reazione 0 assegnatari Vedi su GitHub
area: material/datepicker feature P4
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

### Feature Description

I'm just wondering if we can add the feature of dateFormat to the datepicker

datepicker-input-base.ts

```
@Input displayFormat: string|undefined|null;
@Input parseFormat: string|undefined|null;
```

and in the code:

```
protected _formatValue(value: D | null) {
**const format = this.displayFormat ?? this._dateFormats.display.dateInput;**
this._elementRef.nativeElement.value =
value != null ? this._dateAdapter.format(value, **format**) : '';
}

_onInput(value: string) {
const lastValueWasValid = this._lastValueValid;
**const format = this.parseFormat?? this._dateFormats.parse.dateInput;**
let date = this._dateAdapter.parse(value, **format** );
// ... remaining code
}
```

### Use Case

in this case we can alow different pasing/display format in the same app
the first input will use custom format and the second one use the default one.
both are in the same component
```

Choose a date

DD/MM/YYYY

Choose a date

MM/DD/YYYY

```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia in datepicker-input-base.ts e segui _formatValue e _onInput attraverso l’adattatore delle date e la configurazione date-format esistente. Definisci il comportamento di displayFormat e parseFormat per input descritto negli esempi, quindi verifica che i formati personalizzati e predefiniti coesistano senza modificare il percorso predefinito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.