1

I have three date fields in my form. I'm using jquery datepicker for that fields. I have a code for adding the changed date in ngModel attribute. but that is for one field only.

For Example This is my Component Code

$(".date").datepicker({
  changeMonth: true,
  yearRange: "1:100",
  format: 'mm/dd/yyyy',
  changeYear: true
}).on('change', e => this.SelectedData.Misc1 = e.target.value);

This is my html code

<input type="text" class="form-control date" id="Dat_Misc1" name="Misc1" [(ngModel)]="SelectedData.Misc1">
<input type="text" class="form-control date" id="Dat_Misc2" name="Misc2" [(ngModel)]="SelectedData.Misc2">
<input type="text" class="form-control date" id="Dat_Misc3" name="Misc3" [(ngModel)]="SelectedData.Misc3">

Here the change function assigning the value in one property only. But I need that one as dynamic. Whatever Date Field I select that should fetch the date value on that ngModel.

Please help me. Thanks in Advance..!

Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
  • Check the value 'this.SelectedData' you will get the three model values – Vignesh Mar 30 '17 at 09:18
  • Maybe [this question](http://stackoverflow.com/q/35089638/863110) could help – Mosh Feu Mar 30 '17 at 09:20
  • While binding I'm getting the values @Vignesh.. But If I Change the date via datepicker the values not changing in ng-reflect-model.. !! – Parthiban Subramanian Mar 30 '17 at 09:33
  • Try this$(".date").datepicker({ changeMonth: true, yearRange: "1:100", format: 'mm/dd/yyyy', changeYear: true }).on('input change', e => this.SelectedData.Misc1 = e.target.value); – Vignesh Mar 30 '17 at 09:39

1 Answers1

0

Use jquery on input alongside with the on change event

$(".date").datepicker({
  changeMonth: true,
  yearRange: "1:100",
  format: 'mm/dd/yyyy',
  changeYear: true
}).on('input change', e => this.SelectedData.Misc1 = e.target.value);
Vignesh
  • 2,378
  • 3
  • 25
  • 48
  • Problem is this part Vignesh.. e => this.SelectedData.Misc1 = e.target.value; I don't want this.selectedData.Misc1.. Instead of that I need dynamic ngModel. Now this is assigning the value in only that misc1 ngModel. – Parthiban Subramanian Mar 30 '17 at 11:09