Replace FormControl.disabled by using a CSS or HTML attribute

I have a customized angular date picker where I want to restrict user input by disabling the input field and only allowing selection from the date picker. However, using the "disabled" attribute on the input element is not an option due to conflicts with the form control. Disabling the input using dateFormControl.disable() also poses challenges as it affects the form control status changes required for other functionalities. Is there a CSS-based solution to make the input non-clickable without actually disabling it?

Here is my template code:

<mat-form-field appearance="fill">
          <mat-label>{{'cart.requested-delivery-date' |cxTranslate}}</mat-label>

          <input
            matInput
            [matDatepicker]="picker"
            [min]="data.startDate"
            (dateInput)="formSubmitted$.next()"
            [formControl]="namedDeliveryDateControl"
          >

          <mat-datepicker-toggle
            matSuffix
            [for]="picker"
          >
            <mat-icon
              class="icon-calendar"
              matDatepickerToggleIcon
            ></mat-icon>
          </mat-datepicker-toggle>

          <mat-datepicker #picker></mat-datepicker>

          <mat-error
            *ngIf="namedDeliveryDateControl.errors?.invalidDate"
            class="fs-14"
          >
            {{ 'ecommerce.ndd.validation.error.invalidDate.' + namedDeliveryDateControl.errors.invalidDate | cxTranslate }}
          </mat-error>
        </mat-form-field>

Explanation why direct form control disablement is not feasible:

this.hold(this.namedDeliveryDateControl.statusChanges.pipe(
      startWith(this.namedDeliveryDateControl.status),
      pairwise(),
      tap(([oldValue, newValue]) => {
        this.cartFacade.setEntryFormValidity(this.get('entry').entryNumber, newValue);

        // Reload the cart to refresh error messages for #notOrderable errors in the cart-item-component
        if(oldValue === 'INVALID' && newValue === 'VALID') {
          this.multiCartService.reloadCart(OCC_CART_ID_CURRENT);
        }
      }
    )));

Answer №1

To achieve the desired outcome of a disabled input field, I made use of the 'readonly' attribute along with some custom CSS styling to give it the appearance of being disabled. By doing so, I was able to maintain the form control status without any interference in the disabled state, ultimately meeting both of my criteria.

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

Ensure that the background-color stretches across the entire width of the screen

This text needs to be centered and the background color width should cover the entire screen. Unfortunately, I couldn't find a solution for it here. .carousel-content { text-align: center; bottom: 0px; opacity: 0.8; displ ...

Adjusting Javascript code to convert numerical values in HTML table cells from thousands to millions

Does anyone know how to create a Javascript function for a web report that converts table values to thousands or millions by dividing or multiplying by 1000? The issue is that each value is clickable, meaning it is wrapped in an anchor tag. Is there a wa ...

How to transform the bootstrap 4 hamburger icon into a three dots menu icon using css only

The standard bootstrap 4 navigation bar button showcases a classic hamburger icon. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample03" aria-controls="navbarsExample03" aria-expanded="false" aria-label="T ...

Ways to emphasize several rows by hovering over a single row

One issue I am currently facing in my table is that I have values within a column that span over multiple rows. However, when I hover over these values, only one row gets highlighted (the row with the actual value). I am looking for a solution to highlight ...

Floating CSS containers

Apologies for not including a picture. You can view the design I am trying to achieve here. I am attempting to create two boxes with a third box below them, and another box on the right side of the layout. All enclosed within a larger container. Everythin ...

Using React Native to showcase a background grid of dimensions {height: 10, width: 10}

Hey there! I'm looking to create a grid that can adapt to different device sizes and screen positions, similar to a chess grid. I want to use this as a background to help with sizing and positioning elements like text and images on the screen. Here&a ...

Getting rid of the Horizontal Scroll Bar

Having trouble with a persistent horizontal scrollbar in the "section3__container" container despite attempts to adjust size and overflow settings. Need assistance in removing this unwanted feature. <html lang="en"> <head> <m ...

Generating instances of classes using variables in Typescript

Are there methods to modify the below piece of code in order for it to be compatible with Typescript? public shops: string[] = [ "AShop", "BShop", "CShop", ]; this.shops.forEach((shop, index) => { let instance = new window[shop](index ...

Present user-generated incorrect HTML content without disrupting the webpage layout

My website offers users the ability to input and save text content, which can then be displayed as desired. Users have the freedom to utilize HTML tags for formatting purposes such as design, fonts, divs, tables, and more... However, when it comes to disp ...

What could be the reason behind an Ajax Auto-Complete feature suddenly malfunctioning when moving to a new page within the same website?

Working on a website featuring an auto-complete search box powered by Ajax, Javascript, and PHP. As the user types into the search box, an ajax request triggers a php file to query a database and return possible results. Everything works smoothly until the ...

Easily transform your CSS code into Mozilla-specific CSS with just a click of

Assuming I have the following CSS: border-bottom-right-radius: 20px; Is there a JavaScript library available to automatically convert it to -moz-border-radius-bottomright: 20px; when it detects a user agent that belongs to a Mozilla browser, like Firef ...

CSS - When using both display: flex and position: absolute, the anchor point is shifted

I have a flexbox element with three children. I want the second child to overlap the first child using absolute positioning, like this: Desired Outcome: https://i.stack.imgur.com/i479w.png It's important that the second child appears on top of the ...

Utilizing CSS selectors to pinpoint specific elements on a webpage

As I continue to enhance my CSS skills, I stumbled upon a challenging puzzle that requires me to figure out how to select each individual image on a webpage using selectors. Here is the provided HTML code: <!DOCTYPE html> <html> <head> ...

Angular and Ionic collaborate by using ngFor to pass on the item.id during a (click) event

I have a list of items and I want to dynamically change the height of a card when I click on a button that is located on the card. Can anyone guide me on how to achieve this? I attempted to pass the item.id through a click event and use the id in a functi ...

The image is taking up the entire div instead of just filling the area below the header

I'm currently facing an issue with positioning an image within a container below a header. The problem lies in the fact that the image extends beyond the header's position, filling up the entire container. Below is the code snippet I'm work ...

Error 404 occurs when attempting to retrieve a JSON file using Angular's HTTP

I'm having an issue with my service code. Here is the code snippet: import {Injectable} from '@angular/core'; import {Http, Headers, RequestOptions} from '@angular/http'; import 'rxjs/add/operator/map'; import {Client} f ...

How can I prevent users from registering with the same username in a PHP/MySql user registration system?

I am currently developing a website and need to ensure that each user has a unique username and password. My web page is already connected to a database, which includes fields for users to input their information such as name, username, password, etc. I r ...

Unable to center text within a CSS div rotated 90 degrees due to width limitations caused by rotation; solution involves utilizing flexbox

Currently, I am working on creating a tab positioned on the right side, as illustrated in the image below: https://i.sstatic.net/QGTEB.png The desired width for the tab on the right is only 25px. To achieve this layout, I am utilizing flexbox for the cont ...

Error: Angular was unable to find or read the file for import: ~css-star-rating/scss/star-rating

I'm currently setting up a project that utilizes Angular 6 on the frontend. When I attempt to run the project using the ng serve command, I encounter an error message that reads as follows: ERROR in ./src/styles.scss (./node_modules/raw-loader!./no ...

Combine VS2015 preview with TypeScript 1.3 at your own risk - it may result

After installing VS2015 Preview, I decided to create an MVC project and add a new TypeScript file. However, when trying to compile, I encountered the following error message: The "TypeScript.Tasks.VsTsc" task could not be loaded from the assembly C:&bso ...