0

i have array of objects, here if the date is picked from the datetime calender, the value is not binding to that object, but if i change the date manually then it works, but if i select from calendar then the value is nit binding. I have tried with (change) and (ngModelChange), but both didnt work.

HTML:

<div class="col-6 
            *ngFor="let restrictValue of Restrictions;let i = index">

            <div class="form-group">
              <input type="text" class="form-control onlyDateTime" placeholder="MM/DD/YYYY HH:MM AM/PM"
                [disabled]="!restrictValue.boolValue" [(ngModel)]="restrictValue.datetime" (change)="dateRestriction($event,restrictValue)" (click)="dateRestriction($event, i)"
                [ngModelOptions]="{standalone: true}" >
            </div>
          </div>

TS:

dateRestriction(event,restriction) {
       $('.onlyDateTime').datetimepicker();
      $('.onlyDate').datetimepicker({
        format: 'L'
      });
   $('.onlyDateTime').datetimepicker(
    ).on('dp.change', (e)=>{
      const date = e.date;

      });
  }

DEMO

2
  • @Chellappan from this demo, i should not enable the dates before present day, can that be handled? Commented Feb 14, 2020 at 19:23
  • @Chellappan i need your help Commented Feb 18, 2020 at 16:32

1 Answer 1

1

Try this:

dateRestriction(event, restriction) {
    $(".onlyDateTime").datetimepicker();
    $(".onlyDate").datetimepicker({ format: "L" });
    $(".onlyDateTime")
      .datetimepicker()
      .on("dp.change", e => {
        const date = e.date;
        this.Restrictions[restriction].datetime = date.format("DD/MM/YYYY HH:mm:ss A");
      });
  }
Sign up to request clarification or add additional context in comments.

13 Comments

here am/pm fomat is also required as per requirement
how about that formArray question, can we solve that by today?
I don't know I will check for sure~!
yes please, if that is solved, then i can proceed with my other things, sorry but thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.