Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANGULAR - Disable submit button if form value not changed

i have form for selected date. how to disable the submit button if nothing changed in date form?

my html code

<div class="col-xs-6">
   <label><i class="far fa-calendar-alt"></i> Start <span class="text-danger">*</span></label>
     <input id="startTrip1" name="NgbDate" data-provide="datepicker" ngbDatepicker #d="ngbDatepicker" [markDisabled]="markDisabled" [minDate]="minDates" type="text" class="form-control form-flat" [(ngModel)]="ad.start_date" (dateSelect)="onDateSelect($event, ad)" (blur)="validateInput()" (click)="d.toggle()" [ngModelOptions]="{standalone: true}" [disabled]="form.controls.tripduration.hasError('required')" >
      <div class="text-danger" *ngIf="(ad.start_date == '' || ad.start_date == undefined) && ngForm.submitted">
         * This field is required
       </div>
      <div class="text-danger" *ngIf="form.controls.tripduration.hasError('required')">
      * Fill the durations first
      </div>
 </div>
//submit button
<button class="col-xs-12 text-center text-strong pointer custom-trip-btn" (click)="publishTrip()">
<button class="custom-trip-btn">SUBMIT</button>
like image 619
Soni Silalahi Avatar asked Jan 01 '23 05:01

Soni Silalahi


1 Answers

If you used below code, the button only enabled if user changed value in the form

[disabled]="!(accountForm.valid && accountForm.dirty)"

enter image description here

like image 63
lahiru dilshan Avatar answered Jan 09 '23 18:01

lahiru dilshan