Jump to content

changing color of required input when submitted


Nic727

Recommended Posts

37 minutes ago, Ingolme said:

You can use the CSS :invalid pseudo-class as in the following example: 


input[type=text]:invalid {
  border: 1px solid blue;
}

 

Doesn't work. For some reasons it makes all my required field having my :invalid styles and if I try to submit empty field, the default borders are still appearing. I'm in MS Edge.

Link to comment
Share on other sites

The :invalid selector is the one that you have to use for form fields that had an error. The default border is probably using the outline property or box-shadow property, try setting those to "none". Don't just copy the example code I gave, you have to use the :invalid pseudo-class along with a selector to the specific element you want to change. You also should experiment with different CSS properties to see which one overrides the default style.

Link to comment
Share on other sites

33 minutes ago, Ingolme said:

The :invalid selector is the one that you have to use for form fields that had an error. The default border is probably using the outline property or box-shadow property, try setting those to "none". Don't just copy the example code I gave, you have to use the :invalid pseudo-class along with a selector to the specific element you want to change. You also should experiment with different CSS properties to see which one overrides the default style.

Well… I found that https://css-tricks.com/almanac/selectors/i/invalid/

Look like it show my empty required field as invalid even if I didn't submit yet. Look like it will be better to use JavaScript for that.

My topic should be moved to Javascript…

field.png

 

From what I saw from other contact form out there is that they don't have the "required" in the input and they only have some JS function to check if it's empty. A good idea for customization, but I think that the "required" option is important… But the "required" option prevent the form from submitting, so can't work with ajax text.

Edited by Nic727
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...