What is the process for altering the color of an upload button once the maximum number of file uploads has been surpassed?

Within my HTML code, I have included a line to restrict the number of file uploads to a maximum of 3.

<input *ngIf="uploader.queue.length < 3" #uploadButton ng2FileSelect
       (change)="fileUpload()" [uploader]="uploader" id="supporting-doc-type-{{docType}}"
       type="file"
       class="upload-button"/>
<label for="supporting-doc-type-{{docType}}" *ngIf="uploader.queue.length < 3" class="fake-upload-button" >
  {{'account.uploadNric.uploadDoc'| translate}}
</label>

Currently, the button disappears after the maximum files are uploaded. Now, I wish to change the button's color from blue to red instead of making it vanish. How can I achieve this?

Here is the complete CSS styling:

.upload-button {
  display: none;
}

.fake-upload-button {
  border-radius: 4px;
  color: #fff;
  background-color: #29b6f6;
  padding: 4px 20px;
  cursor: pointer;
}

.col, .col-1, .col-10, .col-11, .col-12, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-lg, .col-lg-1, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-md, .col-md-1, .col-md-10, .col-md-11, .col-md-12, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-sm, .col-sm-1, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-xl, .col-xl-1, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9 {
  padding: 0;
}

.trash-can-icon {
  cursor: pointer;
  font-size: 18px;
}

Answer №1

If you want to make the input field inactive, you can update your *ngIf condition like this:

<input [attr.disabled]="uploader?.queue.length < 3 ? null : ''"/>

To visually indicate that the input button is disabled, you can add a conditional class to the input field:

<input [class.inactive]="!(uploader?.queue.length < 3)"/>

You can use some CSS to style the inactive state:

.inactive{
    background-color: red;
}

The question mark following 'uploader' ensures that it exists before checking its properties.

Answer №2

You can set the disable attribute of an input based on the expression "uploader.queue.length >= 3"

<input
  #uploadButton
  id="supporting-doc-type-{{docType}}"
  type="file"
  class="upload-button"
  [disabled]="uploader.queue.length >= 3"
/>

In your CSS, you can use a selector like this:

input:disabled + .fake-upload-button {
  background-color: red;
}

Here is an example for reference.

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

Missing HTML escape sequences following conversion to a string

The Android test was successfully run using the following code: public static void test() { String text="<html>" + "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\" /> ...

The style remains constant for the animated element despite hovering over it

I am working on a function that makes an element blink continuously. However, when I move my mouse over the element, I want it to stop blinking and be fully visible (opacity 1). Once I move my mouse away, I want the blinking to resume. Here is the code sn ...

How can I trigger the execution of textarea HTML code with an onClick event using JavaScript?

When my fingers are lifted from the keyboard, some code will be automatically executed. I want to trigger this function when I click a button (onclick) instead of using onkeyup. <div id="result"></div> <textarea ...

What is the function of typekit.com and how does it utilize @font-face technology

What is the functionality of typekit.com? Several websites similar to typekit enable CSS designers to utilize custom fonts, but how does it work? Is it possible for me to create a site like typekit myself? What technologies are involved in this process? A ...

Issue with data encoding in React Form

In my React application, I created a stateless component that contains a form. <form action="http://externalsite.com/?param1=value1" method="get" target="_blank" > <input type="text" name="address" id="address" /> <input class ...

Incorporating changing values into dropdown menus beneath the headers of a table

I'm working on a table that has two header rows. The first row shows the title names of the headers, while the second row displays options such as text inputs and select dropdowns for filtering purposes. You can see an example below: JSFiddle <ta ...

Struggling to modify a specific property of an Object using Ajax.BeginForm, only to find that all other properties on the Object become null upon submission

I am attempting to edit the PaymentNotificationEmail field using Razor Code: @using (Ajax.BeginForm("Save", "PaymentLandingPage", new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, })) { <t ...

Utilize flexGrow property to make Material UI Grid container expand dynamically

I've been working on a chat window layout that features my users on the left and messages on the right. However, I'm facing an issue with making both columns extend to the end of the viewport or footer. Below is the component code I'm using: ...

Update Calendar Information Without Reloading the Entire Page

Is there a way to automatically refresh a div that includes a FullCalendar Calendar? I'm looking to refresh the div every 30 seconds to check for new data from the database without having to modify the ViewModel or reloading the page. index.html &l ...

Tips for populating the table with consecutive array values using just a single button

I have an array with values like this: var array = [1, 2, 3, 4, 5, 6, ...]. How can I create a function that, when clicking a button, displays each item in the array in different boxes one by one? For example, on the first click it should display array[0] ...

Adjusting the color of a Bootstrap card's header

I've been struggling with customizing the colors of a bootstrap card header in my application. Here's what I have so far: https://i.sstatic.net/Lv1jk.png Currently, the code I'm using looks like this: <div class="card"> ...

jquery Lightbox triggers not activating

Currently working on a project to create a lightbox with thumbnails for educational purposes. However, I am encountering some difficulties with the code: The event handlers are not triggering after the overlay appears, which has content inserted into i ...

Breaking down large reducer into smaller reducers

I am currently working on a feature reducer (slice reducer) called animals. My goal is to separate these reducers into categories such as mammals, birds, fishes, and more. Initially, I thought this would be a smooth process using the ActionReducerMap. How ...

Navigating through nested <ul> elements using Selenium and C#

Currently, I am attempting to loop through the <li> items within a <ul> object using Selenium with C#. As a newcomer to this, I am exploring ways to simplify the coding process for my testing project. Below is a snippet of the HTML code that I ...

Incorporating visuals into Doxygen documentation

Struggling to add an image with a caption in a doxygen .md file. Adding a caption is easy, but aligning the image left is proving difficult. I've tried several methods, but none have worked successfully. ![Caption](my_image.png "Caption") R ...

Looking for a streamlined method to submit my multiple checkbox selections to the database in a more efficient manner

I am looking for a more streamlined method to submit my multi-selected checkbox form data to my database. Specifically, I am interested in consolidating the values from the Vase Holes Value Checkbox into a single row within my database table instead of h ...

What is the best way to use canvas to precisely draw a line on the display at specific absolute coordinates?

As a newcomer to working with canvas and SVG, I am trying to create a line between two specific coordinates. For example, if I have two rectangles, I need to draw a line connecting their centers: https://i.sstatic.net/Rc6qA.png Here is what I have tried ...

Steps for leveraging pdfMake with live data

Recently delving into Angular, I've been exploring the capabilities of pdfMake. While I successfully incorporated static data, I'm facing challenges when attempting to utilize dynamic data. Any guidance on how to achieve this would be greatly app ...

I don't understand why BodyParser isn't parsing correctly, as everything seems to be in order. Any suggestions on how to fix the "Cannot read property of

I can't seem to understand why the POST request to localhost:3000/api/v1/projects/add isn't saving to the database properly. All other routes are working fine, but the "/add" route returns a 500 internal server error with the message TypeError: C ...

Ways to customize the placeholder for Material input fields in Angular 5

Is it possible to customize the placeholder color in an Angular Material input field? <mat-form-field> <input matInput placeholder="Name"> </mat-form-field> ...