Created
July 25, 2017 12:05
-
-
Save Rodrigo54/95ff2ee48b99bd4719c9dc2898eafd02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mz-input-container class="container-date"> | |
<i mz-icon mz-input-prefix icon="today"></i> | |
<input mz-input mz-validation | |
[label]="label" | |
[dataSuccess]="success" | |
[errorMessageResource]="erro" | |
id="date-input" | |
type="text" | |
class="datepicker"> | |
</mz-input-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:host /deep/{ | |
.container-date > div{ | |
display: flex; | |
flex-direction: column; | |
align-items: flex-end; | |
input, label, mz-error-message > div.invalid{ | |
margin-left: 0; | |
width: 100%; | |
} | |
} | |
mz-error-message{ | |
align-self: flex-start; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { trigger } from '@angular/animations'; | |
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | |
import { Component, OnInit, AfterViewInit, forwardRef, ElementRef, Input } from '@angular/core'; | |
declare var $: any; | |
@Component({ | |
selector: 'app-datepicker', | |
templateUrl: './datepicker.component.html', | |
styleUrls: ['./datepicker.component.scss'], | |
providers: [ | |
{ | |
provide: NG_VALUE_ACCESSOR, | |
useExisting: forwardRef(() => DatepickerComponent), | |
multi: true | |
} | |
] | |
}) | |
export class DatepickerComponent implements OnInit, AfterViewInit, ControlValueAccessor { | |
@Input() erro = ''; | |
@Input() success = 'Data ok!'; | |
@Input() label = ''; | |
@Input() value = ''; | |
picker; | |
element; | |
onChange = (_) => { }; | |
constructor( | |
private elementRef: ElementRef | |
) { } | |
ngOnInit() { | |
} | |
ngAfterViewInit() { | |
this.element = $(this.elementRef.nativeElement).find('.datepicker') | |
this.element.pickadate({ | |
selectMonths: true, // Creates a dropdown to control month | |
selectYears: 15, // Creates a dropdown of 15 years to control year, | |
closeOnSelect: true, | |
monthsFull: [ | |
'janeiro', | |
'fevereiro', | |
'março', | |
'abril', | |
'maio', | |
'junho', | |
'julho', | |
'agosto', | |
'setembro', | |
'outubro', | |
'novembro', | |
'dezembro' | |
], | |
monthsShort: [ | |
'jan', | |
'fev', | |
'mar', | |
'abr', | |
'mai', | |
'jun', | |
'jul', | |
'ago', | |
'set', | |
'out', | |
'nov', | |
'dez' | |
], | |
weekdaysFull: [ | |
'domingo', | |
'segunda-feira', | |
'terça-feira', | |
'quarta-feira', | |
'quinta-feira', | |
'sexta-feira', | |
'sábado' | |
], | |
weekdaysShort: [ 'dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sab' ], | |
today: 'hoje', | |
clear: 'limpar', | |
close: 'fechar', | |
format: 'dddd, d !de mmmm !de yyyy', | |
formatSubmit: 'yyyy-mm-dd' | |
}); | |
this.picker = this.element.pickadate('picker'); | |
this.picker.set('select', this.value, { format: 'yyyy-mm-dd' }).trigger('change'); | |
this.picker.on({ | |
set: (thingSet) => { | |
this.value = this.picker.get('select', 'yyyy-mm-dd'); | |
console.log('Set stuff:', this.value); | |
this.onChange(this.value); | |
} | |
}); | |
} | |
writeValue(obj: any): void { | |
this.value = obj; | |
} | |
registerOnChange(fn: any): void { | |
this.onChange = fn; | |
} | |
registerOnTouched(fn: any): void { } | |
setDisabledState(isDisabled: boolean): void { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment