Interactive checkboxes with data entry fields

Is there a way to achieve the following design? I need to place a textfield next to the last checkbox, but right now, the last checkbox is not aligned with the rest. Does anyone have an idea on how to make this possible? Would using CSS solve the issue?

The Design I am Trying to Implement

This is my current output based on the code provided below. As you can see, the last checkbox is positioned too far from the others.

current-output

HTML Code:

<ul>
  <li *ngFor="let contigency of contingencies;let i = index;">
    <mat-checkbox
      class="checkbox-margin"
      name="contingency"
      color="primary"
      [checked]="currentSelectedContingency(contigency)"
      (change)="changeCurrentContingencies($event,contingency)"
      #checkbox
    >
      <mat-form-field
        appearance="fill"
        *ngIf="contingency.text === 'Other Contingencies'; else text"
      >
        <input
          [disabled]="!checkbox.checked"
          name="otherContingency"
          matInput
          [(ngModel)]="dealDispositionFormFields.otherContingency"
        />
        <span matPrefix *ngIf="dealDispositionFormFields.otherContingency"
          >$</span
        >
      </mat-form-field>
      <ng-template #text>
        <div class="deal-text-label">{{contingency.text}}</div>
      </ng-template>
    </mat-checkbox>
  </li>
</ul>

#ts snippet code:-

contingencies = [
  {id: 1, text: 'Financing Contingency'},
  {id: 2, text: 'Site Plan Approval Contingency'},
  {id: 3, text: 'Permit Approval Contingency'},
  {id: 4, text: 'Tenant Approval Contingency'},
  {id: 5, text: 'Other Contingencies'},
]

changeCurrentContingencies(e:any,rowData:any){    
  if(e.checked){
    this.selectedContingencies.push(rowData);
  }else {
    this.removeSelectedContingency(rowData);
  }
}

Answer №1

Here is a different approach

<ul>
<li *ngFor="let contingency of contingencies;let ind = index;">
    <div [class.d-flex]="contingency.text === 'Different Contingencies'">
        <mat-checkbox class="checkbox-margin" name="contingency" color="primary"
            [checked]="isSelectedContingency(contingency)"
            (change)="updateContingencies($event,contingency)" #checkbox>
            <div class="deal-text-label" *ngIf="contingency.text !== 'Different Contingencies'">
                {{contingency.text}}
            </div>
        </mat-checkbox>

        <mat-form-field appearance="fill" *ngIf="contingency.text === 'Different Contingencies'">
            <mat-label>{{contingency.text}}</mat-label>
            <input [disabled]="!checkbox.checked" name="otherContingency" matInput
                [(ngModel)]="additionalFields.otherContingency" />
            <span matPrefix *ngIf="additionalFields.otherContingency">$</span>
        </mat-form-field>
    </div>
</li>
</ul>

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

Steps for importing jQuery to vendor.ts in Angular 2 webpack

Currently, I am in the process of setting up my Angular 2 app using webpack. As I review the vendor.ts file, I notice this specific structure. // Angular 2 import '@angular/platform-browser'; import '@angular/platform-browser-dynamic'; ...

Error: Unable to access the 'filter' property as it is undefined. TypeError occurred

findLoads(){ if(this.loggedInUser.userFullySetupFlag === 0 || this.loggedInUser.businessFullySetupFlag === 0){ swal( 'Incomplete Profile', 'To find loads and bid, all the details inside User Profile (My Profile) and Business Profil ...

Issues discovered with using Typescript in Visual Studio 2015

I'm having trouble figuring out the issue. Right now, the typescript file is not appearing correctly in Visual Studio 2015. Take a look at the image linked here: https://i.stack.imgur.com/oXXWD.png ...

There was a TypeScript error found at line 313, character 9 in the file @mui/material/styles/experimental_extendTheme.d

Encountering Typescript error while using Material UI component for date range picker Link - https://mui.com/x/react-date-pickers/date-range-picker/ Snippet of the code import * as React from 'react'; import { Dayjs } from 'dayjs'; im ...

Exploring the File Selection Dialog in Node.js with TypeScript

Is it possible to display a file dialog in a Node.js TypeScript project without involving a browser or HTML? In my setup, I run the project through CMD and would like to show a box similar to this image: https://i.stack.imgur.com/nJt3h.png Any suggestio ...

What are the steps necessary to "release" a proprietary Typescript npm package on git?

It seems like a common issue, but I haven't been able to find a solution anywhere... I have two projects written in TypeScript - LibraryA and WebserverB. They are stored in separate git repositories and are set as private projects to keep them from b ...

When implementing .forEach, an object within the array is mistakenly duplicated

Struggling to populate an array of objects with unique data using the .forEach function to display feedback in the Administrator page of my portfolio. However, encountering an issue where the objects from 'd' are getting duplicated in the 'f ...

Creating a backup link for a video player component in NextJs

My aim is to make sure that two video player components in a NextJS application can still access and play videos even when the application is running locally using npm run dev without an internet connection. Currently, these two components.. <HoverVi ...

Encounter a problem while running `ng build` due to a module not

I was looking to automate the building of my Angular project on a separate CentOS 7 machine. Here are the versions being used: Angular CLI: 8.3.23 Node: 13.14.0 OS: linux x64 Angular: 8.2.14 ... animations, common, compiler, compiler-cli, core, forms ... ...

Where Should akitaConfig Be Placed in Angular Development?

Despite my attempt to place akitaConfig directly in the constructor of my app.component.ts file, I am encountering issues with it not properly configuring the data stores created afterwards. My goal is to set resettable to be universally true. Currently, t ...

Grid display not showing scheduled events

I am encountering an issue with fullcalendar in my project where it is not showing the events within the day grid. Despite attempting to adjust the timezone and experimenting with different combinations of times and dates, the problem persists. // Html ...

How to Hide Parent Items in Angular 2 Using *ngFor

I am dealing with a data structure where each parent has multiple child items. I am trying to hide duplicate parent items, but accidentally ended up hiding all duplicated records instead. I followed a tutorial, but now I need help fixing this issue. I only ...

Creating a FormArray with multiple dimensions in Angular 4: A step-by-step guide

For my dynamic form project, I am using the ng-formly npm tool to create a form with sections and tabs, all controlled by a single submit button. According to the library's documentation, I have defined an interface called TabType which specifies diff ...

Encountering the error message "Unable to connect to this site" while attempting to run Angular 8 using Docker Compose

After successfully running npm start for my angular UI application, I encountered an issue when moving API and UI into docker. Every time I tried to access the site, it displayed "This site can’t be reached". Can someone please assist me in identifying w ...

Unable to verify if a nested function is invoked in Jasmine testing framework

Currently, I am in the process of learning how to write test cases using Jasmine. I have been attempting to create a test case that verifies whether the functions defined within a function are actually being called. The function I am testing is outlined b ...

Tips for extracting information from Observable that is supplied with data from an external API

Beginner in the world of Reactive programming (and Angular). I’m eager to create my first data stream and receive something other than an error message in the console output :) Here is what I've attempted: export class AppComponent { requestS ...

Angular Material fixed header and persistent footer

After struggling with this issue for quite some time, I think I may have come up with a solution. My goal is to have a fixed toolbar (navbar) along with a sticky footer that floats at the bottom of the main section. The challenge lies in making sure the fo ...

The HttpClient.get('/') request with {observe: 'response'} is failing to retrieve some headers

Currently, I'm in the process of writing an API GET request by utilizing HttpClient.get(). Upon passing in the option to observe the response, I've encountered an issue where accessing the .keys() does not provide me with any headers apart from C ...

Display and view .dwg files using Javascript, HTML, and Angular

Looking for a way to upload and preview .dwg format images on a page created using js/HTML/angularjs or Angular 2+? I've attempted to use a CAD viewer js library, but the lack of documentation has made it challenging. Has anyone successfully implement ...

Exploring Angular: Looping through an Array of Objects

How can I extract and display values from a JSON object in a loop without using the keyValue pipe? Specifically, I am trying to access the "student2" data and display the name associated with it. Any suggestions on how to achieve this? Thank you for any h ...