Customizing the appearance of Twitter Bootstrap based on the AngularJS input class $invalid

I'm struggling with getting error messages to display properly in my Bootstrap form when using AngularJS. I followed the instructions on this link:
but I still can't figure out what I'm doing wrong.
Any advice?
Thanks

<div class="form-group">
    <label class="col-md-1" for="totalWeight">Total Weight</label>
    <div class="col-md-1">
        <input class="form-control" type="number" max="3000" min="0" name="totalWeight" ng-model="totalWeight" ng-change="calcData()" required>
        <span style="color:red" ng-class="{ 'has-error':pasteForm.totalWeight.$dirty && pasteForm.totalWeight.$invalid"}>
            <br /><span ng-show="pasteForm.totalWeight.$error.required">Total Weight is required!</span>
            <span ng-show="pasteForm.totalWeight.$error.max">Max value 3000!</span>
        </span>
    </div>
    <label class="col-md-1" for="num">%Number</label>
    <div class="col-md-1">
        <input class="form-control" name="num" type="number" min="0" max="100" ng-model="num" ng-minlength="0" ng-change="calcData()" required>
        <span style="color:red" ng-show="pasteForm.num.$dirty && pasteForm.num.$invalid">
            <br /><span ng-show="pasteForm.num.$error.required">Num is required!</span>
            <span ng-show="pasteForm.num.$error.max">Max value 100!</span>
        </span>
    </div>
</div>

Some of the answers suggest that adding a <form> tag might help resolve the issue. One person pointed out that in one section, their page works despite looking bad, while in another, it looks good but doesn't work as intended.

Can anyone provide further assistance on this matter?

<form ng-controller="someName" class="mainDataDiv" id="someName2" novalidate ng-cloak> //it works here

<form id="main-panel" class="col-lg-12" ng-controller="someName" novalidate ng-cloak> //does not work correctly here

Answer №1

You forgot to include the <form></form> tags

Remember to structure it like this:

<form name="pasteForm">
   ....
</form>

Additionally, there is a syntax error in your code: the double quote should come after the closing curly brace in the span tag. Use }"> instead of "}> and switch from using the and operator (&&) to the or operator (||)

<span style="color:red" ng-class="{ 'has-error': pasteForm.totalWeight.$dirty || pasteForm.totalWeight.$invalid}"> 

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

leveraging a callback function alongside the useState hook

I'm facing an issue with the change() function. My goal is to call the filteredData() function after the setState operation is completed. Typically, I would use a callback function for this task, but useState doesn't support callbacks. Using useE ...

The Power of JQuery in Dynamically Adding Script Tags and Executing Code

The objective is to dynamically load script tags via ajax, execute the scripts, and display the content within the script tag (an iframe with a video). Here's the scenario: Imagine a page dedicated to videos. Upon clicking on "video-text," the corres ...

Applying identical values to multiple properties (CSS)

Can we assign a single value to multiple CSS properties at once? border-left, border-right: 1px solid #E2E2E2; Similar to how we can with selectors? .wrapper, .maindiv { ... } ...

Manipulating strings within strings with JavaScript

It's been a strange discovery I made while working with JavaScript. Whenever I try to assign a two-word string to a CSS property, like setting the fontFamily property of an HTML element to "Arial Black", it ends up looking something like thi ...

Loading game resources in advance for future or immediate utilization

I'm currently developing a game UI that involves a large number of image files, totaling around 30MB in size. I've been caching these images to the disk using service workers, but some of them are quite large at 3MB each. Even when they are retri ...

Error in Nuxt build due to missing core-js dependencies in ./node_modules/bootstrap-vue/:variouspath

After working on my nuxt.js project, I encountered some less-than-friendly error messages. Despite performing a clean install by deleting package.lock and node_modules, as well as installing core-js@2 and @babel/runtime-corejs2, the errors persist. ERR ...

Eliminate the commas when listing Google Places types

I am currently utilizing the Google Places API and came across these code snippets at https://developers.google.com/maps/documentation/javascript/examples/place-search-pagination. var map, placesList; function initialize() { var pyrmont = new google.ma ...

Threejs: Illuminating the spotlight with visibility

For my current project, I am attempting to create a visible spotlight similar to the one used by Batman. I want that cone of light that pierces through the night sky. Unfortunately, I do not have any experience with graphics or 3D design, so I am strugglin ...

Inject additional information following user authentication

Hello there! I have successfully developed a REST API using Node.js and StrongLoop, along with an Angular.js based app. After a user logs in, the server sends an accessToken which is stored in cookies. For every request, the accessToken is sent and verif ...

What methods exist for creating visual representations of data from a table without relying on plotting libraries?

Is there a way to plot graphs directly from a Data Table without the need for external graph libraries like plotly or highcharts? Ideally, I am looking for a solution similar to ag-grid where the functionality comes built-in without requiring manual code ...

What could be causing the lack of functionality for my button click in my JavaScript and HTML setup?

Currently, I am attempting to implement a functionality where I have two buttons at the top of my page. One button displays "French" by default, and when I click on the "English" button, it should replace the text with "French" using show and hide methods. ...

Guide to using the PUT method in Node.js Express to update a record using the primary key

I'm currently struggling with understanding the proper usage of the put statement in node js. Here is the code I have been using: app.put("/cars/:id", (req, res) => { //retrieving a record based on id (uuid) e.g. http://localhost:3000/cars/a5ad957 ...

Translating Encryption from Javascript to Ruby

I have an application which utilizes HTML5 caching to enable offline functionality. When the app is offline, information is stored using JavaScript in localStorage and then transmitted to the server once online connectivity is restored. I am interested in ...

Experiencing complications when retrieving API information in my React component

There is a json file available: {"area":[{"id":"1","name":"abc","address":"223 "},{"id":"2","name":"xyz","address":"123 "}] I am trying to fetch and display the data in my component using react and redux. Although I have successfully loaded the url with ...

Unexpected blank space detected at the bottom of the page in Angular 13

Using the NGX-ADMIN template built on Angular 12 has been smooth sailing until an upgrade to Angular 13. With this simple version change, I am now faced with a perplexing issue that I can't seem to pinpoint or resolve. I can confidently say that shif ...

Grab the source attribute of the <img> tag (identified by class) across numerous HTML pages

Here is an example: A website has the URL , where xxxx represents an integer between 1 and 1935. On each page, there may be an <img class="thumbnail" src="Images\Robots\{robotname}.png">. However, not all pages have th ...

Inquiring about paint-order support for HTML elements using @supports

For those looking to create boldly stroked texts in Firefox and Safari, using paint-order and text-stroke (or the prefixed -webkit-text-stroke) is the way to go. Here's an example: h1 { -webkit-text-stroke: 5px red; paint-order: stroke fil ...

What is the most efficient method for incorporating fonts.googleapis.com into CSS files for use on both HTTP and HTTPS pages?

My website functions correctly when accessed through URLs that start with either http:// or default to the http protocol if not specified. However, an error occurs stating that the main.css file cannot be found when the URL begins with https://. The lates ...

Tips for avoiding an endless loop in my React code while utilizing setState within useEffect

Make sure to view the code on codesandbox at this link: https://codesandbox.io/s/bold-hamilton-k1nzs When I execute the code, it triggers an endless loop, causing the entries to grow rapidly. Eventually, the website crashes due to this issue. The state v ...

Function not currently in operation

There seems to be an issue with the script not running or returning any answers. The console is blank. I am attempting to retrieve an answer from the Yandex Translate site (https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/) Code: http: ...