angular-material-components icon indicating copy to clipboard operation
angular-material-components copied to clipboard

Selected time is not being shown in dateTime picker

Open airasyaqub opened this issue 5 years ago • 20 comments

Everything is working fine but selected time is not being shown in UI input field. I have followed all the steps as per docs.

bug

default value of form control is:

this.todaysDate =  moment().utc().utcOffset(this._timeZone);

this.discountForm = this._fb.group({
  startDate: [this.todaysDate, [Validators.required]],
})

airasyaqub avatar Mar 24 '20 11:03 airasyaqub

Hi, Do you use the latest version of @angular-material-components/datetime-picker and @angular-material-components/moment-adapter plz ? It is now v2.0.1. Make sure that you added NgxMatMomentModule instead of NgxMatNativeDateModule in your module. I've alreadry tested your code here and it worked.

h2qutc avatar Mar 24 '20 13:03 h2qutc

Hey. so I have cross checked things. I am using the latest version.

Below is my module file snap modules

I am using custom date adapter to provide my own time zone rather system's one customAdapter adapterCode

and here is my html

html

I still cant figure it out why time is not showing up...

airasyaqub avatar Mar 27 '20 07:03 airasyaqub

You imported MatDatepickerModule that can override the MAT_DATE_LOCALE. Can you try to remove MatDatepickerModule in your module, juste use NgxMatDatepickerModule?
I will add a @Input to hide/show the time part in the picker to prevent the usage of MatDatepickerModule.

h2qutc avatar Mar 27 '20 13:03 h2qutc

@airasyaqub The version @angular-material-components/datetime-picker v2.0.3 is now available. Can you check it out for your problem above please ?

h2qutc avatar Mar 28 '20 23:03 h2qutc

Ok so I updated the package. Thing is if I remove MatDatepickerModule It gives below error obvio: error2

I alos still cant import NgxMatDatepickerModule error3

if I add MatDatepickerModule it gives below error: error1

airasyaqub avatar Mar 30 '20 08:03 airasyaqub

Basically I am importing these modules

NgxMatDatetimePickerModule: For date time functionality, NgxMatMomentModule: To use moment instead native Date functionality, NgxMatDateAdapter: To implement custom date adapter,

What additional modules should I add now ?

airasyaqub avatar Mar 30 '20 08:03 airasyaqub

@airasyaqub In latest version of datetime picker, you have a input @hideTime to hide the time so you would not need to use MatDatepickerModule. For the modules, I think that it is enough. If you can provide an example of codes in https://stackblitz.com/, il will be useful

h2qutc avatar Mar 30 '20 15:03 h2qutc

Thing is we use mat-datepicker-toggle in our component. That's the reason if we don't import MatDatepickerModule we will get error as mentioned above. I went to your live demo code too. You are also importing MatDatepickerModule. Maybe you haven't updated your live demo code with updated package. I will try to provide the stackbliz for you. Thanks

airasyaqub avatar Mar 30 '20 17:03 airasyaqub

Well somehow ur version 2.0.4 fixed the issue.

airasyaqub avatar Apr 10 '20 12:04 airasyaqub

Hello, I've installed v. 2.0.4 but got same problem. The time is not showing ... please help! @h2qutc

ykk1991 avatar Jun 22 '20 16:06 ykk1991

@ykk1991 Do you have any errors on F12 console ? Can you take a snapshot to show how the datepicker is shown ?

h2qutc avatar Jun 22 '20 16:06 h2qutc

datetime-picker-ko

@h2qutc no errors, everything is ok... I've done everything as shown in startblitz project...

ykk1991 avatar Jun 22 '20 16:06 ykk1991

Same issue is happening to me but what i found out, its happening only when i set default options for mat-form-field, like this { provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { appearance: 'outline', floatLabel: 'auto' } }, if i comment this auto, time is visible..

apansky avatar Aug 18 '20 12:08 apansky

OK, i think i found out what the problem might be.

image

as you can see, you are counting that mat-form-field appearence="legacy" wlll be used, legacy does not have any padding so the width: 20px is sufficient, but when you use any other appearence on form field, there is padding on x axis.. so, hope you get what i mean

image

apansky avatar Aug 18 '20 14:08 apansky

@apansky, you are right, is that the problem. For anyone who is using outline style as global, you can add a custom css to resize the time inputs: For me this worked:

    ngx-mat-timepicker {
        .mat-form-field-appearance-outline {
            width: 50px !important;
            max-width: 50px !important;
            .mat-form-field-wrapper {
                padding-bottom: 0;
            }

            .mat-form-field-infix {
                border-top: 0.36em solid transparent;
            }
        }
    }

ramonvic avatar Oct 17 '20 19:10 ramonvic

I am also facing same issue please let me know if anyone got any solution on this...would be appreciate. thanks in advance.

sanjaylikeminds avatar Mar 18 '21 10:03 sanjaylikeminds

"@angular/material": "^14.0.4" "@angular-material-components/datetime-picker": "^8.0.0"

Selected time is still not being shown in text box, Can someone able to help with this issue ?

ankit22687 avatar Jul 14 '22 12:07 ankit22687

{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' }, /* This is the issue. The 'en-GB' is simply a date-only format. Try the below code, and hopefully, it resolves the issue.

providers: [ { provide: MAT_DATE_LOCALE, useValue: { parse: { dateInput: 'YYYY-MM-DD', monthInput: 'MMMM', yearInput: 'YYYY', timeInput: 'HH:mm', datetimeInput: 'YYYY-MM-DD HH:mm', }, display: { dateInput: 'YYYY-MM-DD', monthInput: 'MMMM', yearInput: 'YYYY', timeInput: 'HH:mm', datetimeInput: 'YYYY-MM-DD HH:mm', monthYearLabel: 'YYYY MMMM', dateA11yLabel: 'LL', monthYearA11yLabel: 'MMMM YYYY', popupHeaderDateLabel: 'MMM DD, ddd', }, }, }, ],

Capture

mseltene avatar Oct 02 '23 22:10 mseltene

this did not work for me, can anyone suggest me the solution for this

arunrajac avatar Oct 14 '23 05:10 arunrajac

I added the below style and time display problem fixed for me

    ngx-mat-timepicker {
        .mat-mdc-form-field-flex {
            padding: 0 !important;
        }
    }

hamidh2 avatar Mar 27 '24 08:03 hamidh2