Add CSS styling to the button element when the form is not valid

HTML

<div class="filterButt">
      <input type="hidden" name="reportParams">
      <span class="pull-right">
         <button type="submit" ng-disabled="!filter.$valid" ng-click='filterComponents()' data-toggle="modal" id="filterClose" class="btn-flat default" href="#myModal1"><i class="icon-ok-sign">Save</i></button>
      </span>
</div><!--#filterButt-->

CSS

.btn-flat {
  display: inline-block;
  margin: 0;
  line-height: 15px;
  vertical-align: middle;
  font-size: 12px;
  text-shadow: none;
  box-shadow: none;
  background-image: none;
  border: 0 none;
  color: #fff;
  font-weight: 500;
  border-radius: 4px;
  background: #2b73b0;
  border: 1px solid #3883c0;
  cursor: pointer;
  padding: 7px 14px;
  -webkit-transition: all .1s linear;
  -moz-transition: all .1s linear;
  transition: all .1s linear;
}

Button Image

In this implementation with AngularJS, the goal is to disable the save button when the form is invalid. This can be achieved easily, but there is also a desire to style the button differently, such as graying it out, when validation errors occur.

An attempt was made using ng-class like so:

ng-class="{btn-disable: !filter.$valid }"

Unfortunately, this approach did not have the desired effect. Any suggestions or assistance on how to achieve this would be greatly appreciated!

Thank you.

Answer №1

It seems like the HTML block is missing the form tag, so unfortunately I can't identify what your form class is.

In this case, I will simply utilize the form and button tags in SCSS:

form {
    &:valid {
        background-color: green;
        button[type="submit"] {
             background-color: lightgreen;
        }
    }
}

Answer №2

Consider updating

ng-class="{btn-disable: !filter.$valid }"

to

ng-class="{'btn-disable': !filter.$valid }"

Make sure to pay attention to the single quotes.

Feel free to view this fiddle to see the difference (and check out the error in the JS console!)

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

Border shifts on hover effect

After much trial and error, I finally managed to center two links in a nav bar perfectly on the page. I also added a grey bottom border that spans the entire width of the page, with the hover effect turning it blue under the links. Check out this example: ...

What initiates the call for CSS?

During his instructional video, the creator visits the CodeIgniter website at . When he initially arrives at the site (at 1:32), it appears somewhat odd, almost as if it lacks CSS styling. However, after refreshing the page (1:37), it displays properly. ...

Fix background transition and add background dim effect on hover - check out the fiddle!

I'm facing a challenging situation here. I have a container with a background image, and inside it, there are 3 small circles. My goal is to make the background image zoom in when I hover over it, and dim the background image when I hover over any of ...

Modify the display of multiple divs within a main div

I am facing an issue with a parent div that contains multiple child divs. When there are many children, they all remain in a single row without adjusting into columns. Below is my current HTML: item1 item2 item3 ... <mat-card class="hove ...

Creating a sleek and dynamic bootstrap navigation bar with alignment challenges

I am facing an issue with the navigation bar I created using Bootstrap. It is not aligning as I want it to. I aim for it to be in line with the first image in the photo menu, which opens when you click on the camera icon. This alignment is important to me ...

Content not being displayed by Javascript

I'm having trouble displaying content using JavaScript DOM. Every time I try to run my code, the page comes up blank. Here is an example of my HTML file: <!DOCTYPE html> <html> <head> <title>Radiant HQ</titl ...

aligning two elements within a container to have equal heights

I need to position 2 divs inside a container div. Their height should always be the same, regardless of content. To achieve this, I am using absolute positioning with top and bottom set to 0. Currently, the container div #three collapses and hides the cont ...

Loading Images in Advance with jQuery, Native JavaScript, and CSS

After successfully implementing a method to hover on a small image and load an additional image to the right side of the page, I am now looking to enhance user experience by preloading images. Is there a way to preload an image using JQuery, allowing it t ...

Creating a polished and stylish centered responsive image with Bootstrap 3

I am facing an issue with centering a styled responsive image on my website. Upon debugging, I discovered that the class "portimage" is causing the responsiveness to break. My requirement is to ensure that the images do not exceed 700px in size and have a ...

AngularJS routing not rendering the correct view

I'm encountering a routing problem with my AngularJS/ExpressJS application. The issue is that login.ejs and signup.ejs are partial views, while welcome.ejs serves as the main template. The intention is for these views to load in a ui-view container wi ...

Turn off scroll bar to create a seamless browsing experience on your website

As I work on creating the frontend for a single-page website with seamless scrolling between divs, I'm looking to eliminate mouse scrolling altogether. I understand that using overflow:hidden; can hide scroll bars, but my goal is to make the page scr ...

Tips on how to eliminate focus after choosing a radio button in Angular Material?

This is a snippet from my HTML template file, which includes two Angular Material radio buttons. My goal is to disable the focus on the rings quickly after selecting any radio button. <div id="login-form" class="vh-100 overflow-auto" ...

The flex-basis property seems to be malfunctioning as the image suddenly vanishes when

While my question may seem similar to others, the issue at hand is actually quite different. Here's how it appears in Chrome https://i.sstatic.net/tngvr.jpg Safari https://i.sstatic.net/eE74k.png In Safari, you'll notice that the map disappear ...

Error: The request from http://localhost:8383 to AngularJS MySQL REST API is being blocked due to Access-Control-Allow-Origin policy

Greetings from a newcomer on 'stackoverflow.com'! I'm encountering an issue with my AngularJS Application and I'm hopeful that the community here can provide some guidance. To begin with, I've set up a new maven webapp project ut ...

Combining numerous collapse toggles within a single navbar using Bootstrap

I'm just beginning to work on a new bootstrap site and I want the search bar to be part of a separate collapse toggle. I envision having the search bar toggle on the right side of the navbar, followed by the menu toggle. Here are my questions: How c ...

Guide on how to designate an initial page in an Ionic project

I apologize if this question seems basic, as I am still relatively new to this. While I have a fundamental grasp of how navigation works with angular js, I am struggling to set a starting page. My goal is to make the login page the initial landing page, an ...

Anchor elements and other inline elements not triggering MouseLeave event

Take a look at this CodePen link, particularly in Chrome: https://codepen.io/pkroupoderov/pen/jdRowv Sometimes, the mouseLeave event doesn't trigger when a user quickly moves the mouse over multiple images. This results in some images still having t ...

Variable declared in $scope suddenly losing its definition

Within my directive controller, I've implemented a $watch function as follows: $scope.$watch(function () { return service.abc; }, function(newVal, oldVal) { $scope.abc = {abc: newVal}; }); However, I've encountered issues with the variabl ...

Styling with CSS to create a visual countdown display

I'm trying to replicate the format shown in the image below. https://i.sstatic.net/lnW2C.png Currently, this is the code I have: https://codepen.io/Brite1/pen/wvPrggj (it seems like I just need to adjust spacing and center all numbers/text). I'm ...

When using AngularJs and input[type=date], the date format returned is not the standard yyyy-mm-dd. Instead, it is displayed in the format 2015-06-02T18:30:00

Can someone help me with the code I've used for input type "date"? Currently, it's giving me the date in the format 2015-06-02T18:30:00.000Z, but I actually need it to be in the format 2015-06-02. <input type="date" class="form-control" ng-mo ...