What is the best way to activate form fields in Angular 4 following the click of an edit button?

My goal is to implement a specific functionality within the profile page form. Initially, the form fields should be disabled. Upon clicking the edit button, the form fields should become enabled. However, a problem arises when clicking the edit button again, as the form fields become disabled once more.

Thank you in advance for your assistance.

Form Code:-

    <form name="profile" style="border: none">
      <!-- <fieldset display="none" disabled="disabled" > -->

   <div>
      <ion-list>

 <ion-item>
    <ion-input type="text" placeholder="First Name" class="item" [disabled]="inactive"></ion-input>
    <ion-icon name="person" item-left></ion-icon>
  </ion-item>

 <!-- Repeat for other form fields -->

  <ion-item>
    <ion-input type="text" placeholder="Address Line" style="font-size: 20px;" style="color: #000;" [disabled]="inactive"></ion-input>
    <ion-icon name="pin" item-left></ion-icon>
  </ion-item>

  <!-- Save and cancel buttons -->

</ion-list>

</div>

</form>
  </ion-content> type="submit" value="Modifier" name="btn" style="display:inline" />
 <input type="submit" value="Exporter" name="btn" style="margin-left:10px ; display:inline" /> -->

</div>

</form>
  </ion-content>

Edit button Code:-

  <ion-buttons *ngIf="!toggle" end>

         <button ion-button (click)="changeStatus()">
               <h3> <ion-icon  name="create"></ion-icon></h3>
          </button>
        </ion-buttons>

.ts file for the changeStatus method:-

    export class ProfilePage {
 newItem:number[]= [];
mobileLength:number[] =[];
public inactive:boolean = true;


 constructor(public navCtrl: NavController, public navParams: NavParams) {

 }

 changeStatus(){
    this.inactive = !(this.inactive);
  }

Answer №1

To establish your inactive status, simply set it once by following the steps below:

updateStatus(){
   this.inactive = true;
}

By changing the value of the inactive property, you alternate between true and false, resulting in the toggling effect.

Answer №2

To make changes, you have two options:

modifyStatus() {
  this.inactive = false
}

Alternatively, you can choose to keep the same function but make sure to hide the Edit button once it has been clicked.

For instance, if the Edit button is clicked, display a Cancel button to deactivate the form again.

<ion-buttons *ngIf="!toggle" end>
  <button ion-button (click)="modifyStatus()" *ngIf="inactive">
    <h3><ion-icon  name="create"></ion-icon></h3>
  </button>
  <button ion-button (click)="modifyStatus()" *ngIf="!inactive">
    <h3><ion-icon  name="close-circle"></ion-icon></h3>
  </button>
</ion-buttons>

I trust this information is useful to you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered during conversion to Typescript for select event and default value

When trying to set the defaultValue in a Select component, TSlint throws an error - Type 'string' is not assignable to type 'ChangeEvent<HTMLInputElement> | undefined - for the code snippet below: const App = () => { const [ mont ...

What is the reason this union-based type does not result in an error?

In my TypeScript project, I encountered a situation that could be simplified as follows: Let's take a look at the type Type: type Type = { a: number; } | { a: number; b: number; } | { a: number; b: number; c: number; }; I proceed to defi ...

Customize the height of individual carousel items in Primeng carousel

Hey there, I'm currently using the primeng carousel component and running into an issue where the carousel height is always based on the tallest item. I am looking to have an automatic height for each individual carousel item instead. Do you think th ...

Refreshing an Angular page with parameterized routes on IIS results in a blank page

In an effort to resolve the 404 error that occurs when refreshing a page on my Angular application, I made modifications to the web.config file within the website folder on IIS. The code snippet added is shown below: <rule name="AngularJS Routes&qu ...

"Selecting the appropriate version of Angular for your project

Hello there, I am a beginner in this field and have a question. I am currently working on an app using Ionic with Angular version 4. I am considering switching to Angular version 1. Can you help me out with the steps to do so? Thank you! ...

Transforming strings of HTML into objects in the DocX format

After developing a TypeScript script that transforms a JSON string into a Word Doc poster using Docx, I encountered a hurdle. Certain sections of the JSON may contain HTML tags, such as <br/>, <i>, <p>, and I need a way to pass the stri ...

Instructions on setting a photo as a background image using a text-based model

I'm a beginner with Angular so I may have a simple question. I am using an image from the Google API, which is not a URL. How can I set this image as the background-image in a CSS tag that only accepts URIs? Thank you! ...

The value stored in Ionic Storage will only be visible on the HTML page after a refresh is performed

After updating my Ionic Storage values, they are not showing up on the HTML page until I reload it. I have researched similar issues faced by others, but the solutions I found either do not work or are no longer applicable due to changes in the Ionic versi ...

Preventing page reload when altering parameters in Angular 9

I have recently utilized Angular9 along with PathLocationStrategy {provide: LocationStrategy, useClass: PathLocationStrategy}, The issue I am facing is: Whenever I use form.submit() to send data to the backend, the backend then redirects back to the c ...

The mat-datepicker is being displayed beneath the content

My Angular material design datepicker is displaying underneath the content. Within my module, I have a component that is rendered inside app-root. This component includes a mat-stepper with a mat-datepicker inside one of the steps. This is how the genera ...

ngModel Error: Unable to retrieve the 'name' property of an undefined value

I have a JSON file that displays different levels of data, some in regular format and some as arrays as shown below. [![enter image description here][1]][1] However, I keep encountering an error message like the one below: [![enter image description her ...

Issue: Unable to locate a change supporting element '[object Object]' of the type 'object - Angular 7'

An angular service has been created for the specified purpose: CheckTicket(barcode, codEspec, diaHoraEspec):Observable<Ticket[]>{ //read ticket return this.http.get<Ticket[]>(`${this.checkticket_url}${barcode}?token=${this.token}&a ...

Building a table with Next.js

I need assistance in displaying users and their metadata in a table on my website. Here is the code snippet I have: const apiKey = process.env.CLERK_SECRET_KEY; if (!apiKey) { console.error('API_KEY not found in environment variables'); proc ...

An issue occurs with Material Dialog getting stuck when it is triggered by clicking on a Leaflet

I'm currently working on a project that involves using a map with ngx-leaflet. When a user clicks on a marker, I want to display a Dialog from Angular Material. Although the Dialog opens successfully, when I click the close button, it reopens and the ...

The issue with the demo variable not functioning properly within the ngOnChanges method of the child component

I am facing an issue in child.component.ts where I am using the demo variable with input(), but it is not showing up in the developer console. app.html <input type="text" placeholder="text" #val> <br> <button (click)="submitValue(val)"> ...

Connect the child content to the form

Are there any methods to connect a projected template (ContentChild) to the form specified on the child, such as adding formControlName after it has been rendered? I am having difficulty in finding relevant information online, possibly due to using incorr ...

Converting typescript path aliases into local file paths

Just dipping my toes into typescript and grappling with module resolution. The problem seems straightforward (or so I think), but there's something off about my tsconfig.json. If my folder structure looks like this: + release + definitions + ...

Document: include checksum in HTML

I have a set of three files. The file named loader.js is responsible for creating an iframe that loads another file called content.html, which in turn loads content.js. I have made loader.js publicly available so that other users can include it on their ow ...

Exciting ngClass variation

I am facing a challenge of adding multiple classes to an element, with one of them being conditional. After referencing the documentation, I came across this method: <some-element [ngClass]="{'first': true, 'second': true, 'thi ...

Unexpected behavior encountered when running Angular 8 radio button checked function

I have an Angular 8 web app with some unique logic implemented as shown below: HTML: <div *ngFor="let item of selectedItems;"> <input type="radio" [(ngModel)]="mySelectedItem" [value]="item.key" (ngModelChange)="setCh ...