1

when the user made an unnecessary changes and dont want to save it then it should reset the values to previous values when the user clicks on cancel button.Any solutions

<div class="org-event" *ngIf="org.eventsettings">
    <div class="event-title">Title</div>
    <br/>
    <label><input type="number" [(ngModel)]="expires" pattern="^[0-9]{1,3}$"/> An Event Begins at {seconds}</label>
    <label *ngIf = "condition1" ><input type="number" [(ngModel)]="org.value"/> value</label>
    <label *ngIf = "condition2" ><input type="number" min="1" max="3" pattern="[1-3]" [(ngModel)]="org.members"/> Quantity</label>

    <br/>
    <button class="even-success" (click)="save(org._id);"> Save </button>
    <button class="even-success" (click)= "org.eventsettings=''"> Cancel </button>
</div>
Trang D
  • 333
  • 5
  • 16
  • where do the previous values come from? do you just want to clear the input fields? can you use javascript? – DCR Mar 11 '20 at 15:56
  • 1
    not sure if it will work with angular (haven't touched it for quite a while) but have you tried adding a or otherwise create a button and on click clear your model values via js. – Nick Surmanidze Mar 11 '20 at 15:57
  • @NickSurmanidze reset , this works fine but only with first label in my code. rest 2 labels value and members are not. so i tried this `` but it resets wrongly i just want to discard the changes of one particular label but it resets everything. any here please – Trang D Mar 13 '20 at 06:19

1 Answers1

0

When the user clicks the cancel button, call this function:

function clearValues() {
  var inputs = document.getElementsByTagName("input");
  while (i < inputs.length) {
    inputs[i].value = "";
    i++;
  }
}

All in all, it gets all of the inputs on the page and sets their values to a blank string.

micahlt
  • 377
  • 2
  • 11