How to clear and rest solid border - javascript

I've added a red border to my input boxes on error generated during form validation
<input id="cardnumber" />
The border is set to red in my javascript using:
$(cardnumber).css({ "border":' solid #ff0000'})
Now I would like to clear the solid border when the user resolves the error:
I tried:
$(cardnumber).css({"outline":'none'})
$(cardnumber).css({"outline":'0'})
None of of the above works.
Whats the correct css to reset the border?

Set the border to none:
$(cardnumber).css({"border-color":'black'});
But rather than changing CSS explicitly, it's generally better to use classes and put the styles in your CSS file.

Try border: none;
Outline is not the same as border

Keep the value of the border css before the error in a variable and reapply after:
$borderbefore = document.getElementById('cardnumber').style.border;
...
//error
$(cardnumber).css({ "border":' solid #ff0000'})
...
//correction
document.getElementById('cardnumber').style.border = $borderbefore;

Related

How can I change the border color on my <select> element without effecting bootstrap css styling?

I have a bootstrap (v4.5.3) form, where my selects look like this in firefox:
When someone tries to submit the form, I have some JS code that runs, and does validation. One of the things it checks for is that someone actually chose an option, and didn't leave it on -- Select an Option --. When I detect this, my javascript would stop form submission, and highlight the option by setting the border to red:
ELEMENT.style.borderColor = "red";
Unfortunately, when I do that, my select loses whatever styling bootstrap put on it, and looks like this:
I left the bottom one untouched for easy comparison.
Am I highlighting it wrong? Is there some css class I'm supposed to use instead of changing the borderColor?
Edit: See https://jsfiddle.net/xbqucoLp/ for example
Bootstrap actually comes with validation CSS built in. The style of the select in bootstrap is different to what you have in your question so it may not be to your liking. It does however keep the select arrow consistent unlike what you currently have.
See https://getbootstrap.com/docs/5.0/forms/validation/ for details
Here is a working fiddle: https://jsfiddle.net/0gqL7641/1/
The advantage of using this is that when you choose an option it changes from red to green.
If the above is unacceptable to you, then the following will work:
You can use outline instead of border and this doesn't change the styling of select
this.style.outline = "solid 1px red";
Another way of changing the outline without touching border is to use shadow
.redOutline {
-webkit-box-shadow: 0px 0px 3px 3px rgba(255,0,0,0.5);
box-shadow: 0px 0px 3px 3px rgba(255,0,0,0.5);
}
and use the following to add the outline
this.classList.add("redOutline");
You can tweak the shadow CSS using this tool https://html-css-js.com/css/generator/box-shadow/
Have you tried adding a class to the element instead?
like this
element.classList.add("mystyle");
that might work as long as the only thing that class contains is a border color with !important
Ah I didn't realize there was a difference sorry. Usually for these custom selects, there are classes that overlay the browser select to get custom features. I would see if you can target those classes and change their border color. Looking for the elements in the browser dev-tools allows you to change their css in the browser to test if you can do that to see what element you need to target.

Why is the contact form barely visible? We want the contact form to be white and brighter

Our contact form is barely visible. We can't figure out what's going on... if you go to the page you'll see what I mean. Github page: https://tcffo.github.io/
The border for your input fields have an opacity of 0.2 and it's a grey color. I'd change the border to white and the opacity to 1 border: 1px solid rgba(255,255,255,1) and also add a background-color as suggested by others here, for instance background-color: rgba(255,255,255,0.2). I hope this helps. The existing CSS for your input-fields are found on line 1720 in main.css.
give background color to your form or form wrapper
or
give border to your form elements
You can apply below two rules or one of them
<style>
/*Background for your form*/
#contact-form{
background-color:#YOUR_COLOR;
}
/*Border for form elements*/
#contact-form input{
border:1px solid #FFFFFF;
}
</style>
This question has no definitive answer, but some options to make your form clearer are to:
not have an image underneath your form at all
bolden the text
blur and possibly darken the background (like frosted glass)
block out or darken the background just underneath the form controls
The first and last options are the best in my opinion. The reason they're so dark is because they're placeholder values, and making them white, the same colour as your input text, is a horrible idea because then it becomes unclear if the text is just a placeholder or not.

Expand hover area while keeping background color

I have a div that I want to expand the "hover area" of. (If your mouse is just outside of the element, the css :hover selector should still be in effect.)
I tried creating a transparent border: (border:10px solid transparent;) Unfortunately, my div has a background color, and the background "leaked" into the border area. (See fiddle for demonstration of the issue.)
I also tried using outline instead of border, but the outline doesn't seem to "count" as a part of the element when it comes to hovering. (It looks right, but won't detect the extra hover area.)
Is there any way to do this with plain CSS (preferably not many extra elements)? If not, is there a simple method using vanilla JS (no jQuery)?
$("#toggle").click(function(){
$("#attempt").toggleClass("border");
});
#attempt {
width:100px;
height:200px;
background:#aaa;
margin:50px;
}
#attempt.border {
margin:20px; /* Change margin to keep box in same place after border adds size */
border:30px solid transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div id="attempt"></div>
<button id="toggle">Toggle Border</button>
<p>Border (in the ideal case) would not change the element's background. However, adding the 30px border (even when transparent), will cause the background to change size.</p>
All you need to prevent the background to leak is the box-sizing property. It's a very important one. Just add it to #attempt:
#attempt {
box-sizing: border-box;
}
Check out the updated fiddle here. You can learn more about box-sizing here.

why css not apply on form in angular js

I apply css in form it should apply when my form is invalid .I also write important but nothing happen .In other words I make a dynamic form from json ,Now I need to validate that form .so I apply css which is not working.why I am apply css because some one suggest that in this how to validate form using $pristine and $dirty in angular? you please why it is not apply
here is my plunker
http://plnkr.co/edit/ECLvOstUxq5tIDrYicF2?p=preview
/* Styles go here */
.ng-invalid {
border :1px solid red !important;
}
.ng-pristine {
border :1px solid blue !important;
}
.ng-pristine {
border :1px solid blue !important;
}
Updated plunker
http://plnkr.co/edit/ECLvOstUxq5tIDrYicF2?p=preview
I press login button nothing happen
You need to update your css into this
input.ng-invalid {
border :1px solid red !important;
}
the class ng-invalid applies to the form as well since it AngularJS detects that the form is invalid so it applies the class to the form.
Edit
It seem that you are using a third party module for your forms. It has it's own validation styles so we have to use it. Here are some notes:
I added the novalidate directive to your formly directive. This will prevent the browser to trigger its default validation, the browser's default validation will not trigger the ng-submit function if it finds an error.
I added an ng-class="{'form-submitted':submitted}" to the form directive itself. (This is similar to the approach of PatrickEvans' answer
In relation to Item 2, I modified the CSS to this. The red border will be applied if the form-submitted class is applied to the parent form.
.form-submitted input.ng-invalid {
border :1px solid red !important;
}
See Plunkr
You have invalid style values: 1 px solid red !important you have a space between the number and px which makes it invalid so it does not render that style.
If using Chrome, you can look at an elements applied styles and if there is a warning symbol next to the style (and has a line through it) it means it is an invalid value. Not sure what the other browsers Developer Tools looks like for this but this is what Chrome's looks like:
As for making the css only apply after hitting the login button you will need to setup a check. You can do this by using the ng-class directive
css
.ng-invalid.apply {
border :1px solid red !important;
}
html
<input type="email" ng-class="{apply:loginAttempted}" />
<button type="submit" ng-click="loginAttempted=true" />
the ng-class will apply the style apply to the element when loginAttempted is a truthy value. So when the element gets the ng-invalid and the apply classes then the border will be rendered.

can not remove the dotted border from submit button on Firefox

I am using Firefox 27.0.1. I have a third party form that I only have acces to its CSS style, and not to the html code.
I tried to remove the dotted border on the submit button using: div.submit input[type="submit"] {outline:none;} but it still appear...
any other way to remove it?
That looks like a focus event, try this:
div.submit input[type="submit"]:focus {
outline:none;
}
Check if you have 'focus' inside your CSS file which focuses the item as a dotted.
Thanks for all answers,
what help me to get rid from the dotted border is:
div.submit input[type="submit"]:focus {outline:none;}
div.submit input[type="submit"]::-moz-focus-inner {border:0;}

Categories

Resources