Display an Asterisk Icon for md-input fields with lengthy labels

Documentation states that md-inputs add an asterisk to the label if it is a required type. However, when input containers have width constraints and long labels, the label gets truncated and the asterisk becomes invisible. From a user experience perspective, this makes it difficult to determine which fields in the form are required without interacting with them.

Below, I have provided a small codepen to demonstrate this issue. Both input fields are marked as required with different titles.

CodePen - Codepen

Ideally, I would like to trim the long text and ensure the asterisk is visible.

Any help or suggestions would be greatly appreciated :)

angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
  .controller('AppCtrl', function($scope) {
    $scope.project = {
      description: 'Nuclear Missile Defense System',
      rate: 500
    };
  });
.md-block {
  max-width: 300px;
}
<div ng-controller="AppCtrl" layout="column" ng-cloak="" class="inputdemoErrors" ng-app="MyApp">
  <md-content>
    <form>
      <md-input-container class="md-block"> <label>LongTitleLongTitleLongTitleLongTitleLongTitleLongTitleLongTitle</label>
        <input ng-model="vm.job.title" ng-required="true">
      </md-input-container>
      <md-input-container class="md-block">
        <label>ShortTitle</label>
        <input ng-model="vm.job.title" ng-required="true">
      </md-input-container>
    </form>
  </md-content>
</div>

Answer №1

Are you attempting to accomplish this task?

Link to CodePen

.md-required {
  padding-right: 10px !important; //essential padding for visibility 
  width: auto !important; //adjusting width for asterisk placement
}

.md-required:after {
  color: red !important;
  width: 100%; //matching label width
  position: absolute; //ensuring positioning matches label
  left: 0; //aligning with label
  text-align: right; //placing asterisk on the right side
}

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

The code for populating the lookup does not perform as expected on the initial attempt

I've encountered an issue with my JavaScript code on a form where it auto populates 2 lookup fields with the current user when the record is being created. Most of the time, this function works as intended. However, I've noticed that during the f ...

JavaScript: A timer that relies solely on the concept of TIME

Hello all, I have a specific question regarding starting a timer in JavaScript for a test scenario. Despite researching on my own and seeking help on various platforms, I haven't found a solution that fits my requirements. I am looking to implement a ...

Angular's promise delay is failing to meet expectations

Unfortunately, I'm unable to display the complete code snippet here. However, I have come up with a summary of the issue I am facing. I have implemented a service and controller in my code. Within the service, I included a 2-second timeout for my gro ...

The editor is locked and choices are displayed in a vertical orientation

I'm currently experimenting with using draft js in my project to create a wysiwyg editor. However, I've encountered an issue where the editor appears vertically instead of horizontally when I load the component. Any idea why this might be happen ...

Live Search: Find Your Answers with Ajax

I've come across this issue multiple times, but haven't found a solution that fits my specific requirements. I've encountered several URLs with links like example.com/ajax/search?query=Thing I'm currently working on a header and using ...

Using PHP's include/require method with a dynamic path

Looking for assistance with my issue! Ajax is returning the correct information and displaying it in an 'alert(html)' on 'success'. The PHP code echoes $idName and $path correctly on the carrier page where the code resides. There are no ...

After incorporating some movement effects into my menu, suddenly none of the buttons were responding

While working on my website and trying to add a close menu button, I encountered an issue where all the menu buttons stopped functioning. Here is the HTML code snippet: <div id="openMenuButton"> <span style= "font-size:30px;cu ...

CSS Animations are effective in CodePen, but unfortunately, they do not function properly once integrated into an ASP.Net project

I created a unique design on codepen with a background animation, which functions properly there. However, when I integrate it into my ASP.Net Core project, the animation doesn't work as expected. The file references seem correct because the backgroun ...

Using HTTPS, you can access Flask from AJAX

I have encountered numerous inquiries concerning this issue, but none have proven effective for me. I recently switched my domain from HTTP to HTTPS. Everything was functioning properly on HTTP. The main issue lies in the fact that my javascript and flask ...

Issue: The specified source path cannot be found: resourcesandroidicondrawable-hdpi-icon.png

I am encountering an issue while attempting to retrieve an APK file from an Ionic project on a Mac. The error message I receive is as follows: "Error: Source path does not exist: resources\android\icon\drawable-hdpi-icon.png" Does a ...

The navigation bar on the website highlights vibrant green arrows next to the

I'm having trouble implementing a bootstrap menu on my website using the code provided by Bootstrap. The menu is not displaying correctly and instead showing small green UL arrows. I have JavaScript and Bootstrap scripts in my project. Is there a way ...

Error 404 - The Web API is missing and needs to be integrated with AngularJS

Here is the controller code snippet: [HttpGet] [ActionName("Email")] public HttpResponseMessage GetByEmail(string email) { Users user = db.Users.Find(email); if (user == null) { throw new HttpResponseExcept ...

I keep encountering an error stating that parameter 1 for 'FormData' is not of type 'HTMLFormElement'. I am struggling to resolve this issue on my own. Can someone please assist me with fixing this problem?

Here is the snippet of code that I am struggling with: const authForm = useRef(); const handleSubmit = (e) => { e.preventDefault(); //formData let form = new FormData(authForm.current); console.log(form) } This code snippet shows how I added a ...

There was a serious issue: The mark-compacts were not working effectively near the heap limit, resulting in allocation failure - the JavaScript heap ran out of memory during the

I recently set up a t2.micro server on AWS and encountered an issue when running our application with the command "sudo npm start". The error message I received was: "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript he ...

What's the best way to use JavaScript to obtain the width of a 'css-pixel' based on a media query?

While there have been discussions on how to determine device sizes using media queries like Twitter Bootstrap, I am looking for a reliable way to achieve the same output using JavaScript. Specifically, I want to get the CSS media query pixel number rather ...

What causes my paragraph textContent to vanish after briefly displaying its value?

As a beginner in JavaScript and HTML, I am taking on the challenge of learning these languages from scratch independently. I have encountered an issue with my code where the word "Hi!" briefly flashes below the "Click Me!" button before disappearing compl ...

Bigcommerce encounters a 401 error during the payment processing, triggered by API with error code 10001

I recently started working on integrating the Bigcommerce payment API and I am facing issues with solving the 401 unauthorized error. Below is a sample of the data that I have tried: { "payment": { "instrument": {}, "payment_method_id": "cod", "amoun ...

What is the best way to choose an HTML element based on the attributes of its child nodes in CSS?

Take this scenario for instance: <tr> <td align="center">123</td> <td class="someclass">abc</td> </tr> My goal is to target all <tr> elements that contain a <td> with the class attribute set to someclass. ...

Experiencing issues while trying to publish on Cloudflare Workers?

To organize my project, I decided to create a folder named workers. Inside this folder, I followed these steps: Firstly, I initiated the project using npm init. Next, I installed @cloudflare/wrangler by running npm i @cloudflare/wrangler. This action resul ...

Angular Markdown Styling: A Guide

Currently, I am using Angular and Scully. I would like to add style to the image in a markdown file within Angular, but I am unsure of how to accomplish this task. The image is currently displaying too large. Can anyone provide me with useful advice on how ...