I have an Angular 5 component that is basically just a label and input
<div class="form-group">
<label for="wwid">WWID</label>
<input id="wwid" required ...lots of attrs...>
</div>
Using CSS I've then defined a style:
.ng-invalid:not(form) {
border-left: 5px solid #a94442; /* red */
}
When the field is blank, I'm getting two red borders. The one on the input field that I want, but also one to the right of the label that I do not want. How do I get rid of the red line on the label?
Here's the actual full HTML that used by the component.
<ng-template #listSelectionFormatter let-r="result">
<span>{{r.wwid}} - {{r.fullName}}</span>
</ng-template>
<div class="form-group">
<label *ngIf="labelText" for="wwid">
{{ labelText }}
<span *ngIf="isRequired"> <sup class="requiredIndicator">*</sup></span>
</label>
<!-- inputFormatter is the format for what is placed into the input field after choosing from the dropdown -->
<input id="wwid" type="text"
class="form-control"
placeholder="Search by WWID, IDSID, Name or Email"
(selectItem)="onWorkerSelected($event.item)"
(input)="onTextFieldChanged($event.target.value)"
[ngModel]="selectedWorker"
[ngbTypeahead]="search"
[inputFormatter]="selectedResultsFormatter"
[resultTemplate]="listSelectionFormatter"
[disabled]="disabled"
[required]="required"
/>
<span *ngIf="searching">searching…</span>
<div class="invalid-feedback" *ngIf="searchFailed">Lookup failed.</div>
</div>
The requiredIndicator thing is just for an older style I was using to show an asterisk if it was required, and used this CSS:
.requiredIndicator {
color: red;
font-size: larger;
vertical-align: baseline;
position: relative;
top: -0.1em;
}
I'm importing a mailing list into MailChimp and am having trouble with implementing interest groups correctly. Here's my situation: subscribers have opted in to receive updates for one or more geographic area (NYC, Boston, etc.) The vast majority of users belong to only one group, but it's important to allow people to sign up for more than one group. MailChimp groups work for this perfectly, EXCEPT for the fact that groups can't be made required fields...except using the advanced form design mode.
Per the Mailchimp documentation:
Group fields can not be set to required for a sign up form. The logic in our database is such >that Groups shouldn't be required because they are considered to be a list of options or >interests for segmenting and it is valid for someone to have no interests. If you are an >?>advanced user or have a developer that can help out, a required Groups field could be custom >coded using the Advanced forms option(available only to paid accounts) in your account.
I've done a ton of searches to find even the first steps to addressing this through the advanced form mode but have come up empty so far. I'm no expert on HTML/Javascript/PHP but I know enough to tinker and get things done through trial and error. Also, the form will ideally be hosted on a WordPress page.
I have experienced same problem with you.
What i did is added a javascript validation to the Mailchimp embed code.
This is the example of the code. I was using radio buttons.
I'll just remove the form action button for personal reasons
<!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; width:650px;margin:auto;}
.mc-field-group{width:50% !important;margin:auto;}
.mc-field-group.input-group{width:96% !important;margin:auto;}
#mc-embedded-subscribe{
margin: auto;
width: 150px !important;
height: 30px !important;
font-size: 15px !important;
background: #eb593c !important;
position: relative !important;
color: #fff !important;
margin-left: 38% !important;
}
/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
<label for="mce-EMAIL">Email Address <span class="asterisk">*</span>
</label>
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
<label for="mce-FNAME">First Name </label>
<input type="text" value="" name="FNAME" class="" id="mce-FNAME">
</div>
<div class="mc-field-group input-group">
<strong>How Often Would You Like to Hear From Us: <span class="asterisk">*</span></strong>
<ul><li><input type="radio" value="4" name="group[10709]" id="mce-group[10709]-10709-0"><label for="mce-group[10709]-10709-0">Somewhat Weekly: THRIVING IS THE NEW YOU Blog Posts sent via Email</label></li>
<li><input type="radio" value="8" name="group[10709]" id="mce-group[10709]-10709-1"><label for="mce-group[10709]-10709-1">Monthly Vibrancy Roundup: It's like a E-Newsletter but way groovier.</label></li>
</ul>
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_ef38bee7ba91bb0815db87917_22d8d62dc8" tabindex="-1" value=""></div>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
</form>
<script type="text/javascript">
var forms = document.getElementById('mc-embedded-subscribe-form');
try {
forms.addEventListener("submit", function(event)
{
var off_payment_method = document.getElementsByName('group[10709]'); //this is the name of the radio buttons
var email = document.getElementById('mce-EMAIL');//email field
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
event.preventDefault();
return false;
}
var ischecked_method = false;
for ( var i = 0; i < off_payment_method.length; i++) {
if(off_payment_method[i].checked) {
ischecked_method = true;
}
}
if(!ischecked_method){
alert("Please choose from How Often Would You Like to Hear From Us:");
event.preventDefault();
return false;
}else{
return true;
}
}, false);
} catch(e) {
forms.attachEvent("onsubmit", function(event)
{
var off_payment_method = document.getElementsByName('group[10709]'); //this is the name of the radio buttons
var email = document.getElementById('mce-EMAIL');//email field
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
event.preventDefault();
return false;
}
var ischecked_method = false;
for ( var i = 0; i < off_payment_method.length; i++) {
if(off_payment_method[i].checked) {
ischecked_method = true;
}
}
if(!ischecked_method){
alert("Please choose from How Often Would You Like to Hear From Us:");
event.preventDefault();
return false;
}else{
return true;
}
}); //Internet Explorer 8-
}
</script>
</div>
<!--End mc_embed_signup-->
Have you tried adding class="required" to each group field in the advanced editor? When I look at my required fields, they are declared with this class (except the email, which seems to have a special "email required" class:
<div class="mc-field-group"><label for="mce-FNAME">First Name <span class="asterisk">*</span>
</label>
<input class="required" id="mce-FNAME" type="text" name="FNAME" value="" /></div>
<div class="mc-field-group"><label for="mce-LNAME">Last Name </label>
<input id="mce-LNAME" type="text" name="LNAME" value="" /></div>
In this example, taken from one of my forms (hosted on a WP page), FNAME is required, but LNAME is not.
My navbar has dropdown "fieldsets" for login and search like this:
<div class="nav-button" id="nav-box">
<a class="inside-link">
<span id="inside-text">Sign in</span>
</a>
<fieldset id="menu-box" class="menu-box">
<form method="post" id="forms" class="forms" action="checklogin.php">
<label for="username">Username or email</label>
<input type="text" id="username" name="username" value="" title="username" tabindex="4">
<label for="password">Password</label>
<input type="password" id="password" name="password" value="" title="password" tabindex="5">
<input type="submit" id="small-btn" value="Sign in" tabindex="6">
<input type="checkbox" id="remember" name="remember_me" value="1" tabindex="7">
<label for="remember">Remember me</label>
<br />
Forgot your password?
<a id='forgot_username_link' title="If you remember your password, try logging in with your email" href="#">Forgot your username?</a>
</form>
</fieldset>
</div>
I have a fiddle here: http://jsfiddle.net/WBrns/5/
While input boxes like "search" "username" and "password" are focused, I'd like the associated dropdown to not disappear so users don't have to keep their mouse within the dropdown while typing.
Line 288 in the CSS was our first attempt which obviously doesn't work. My site already includes jQuery so any js/jquery solution is acceptable (since I think it's not possible with pure css)
Thanks!
On your hover style, make sure the attributes have the !important command and then use the code below while remembering to substitute the id's and classes to what you need:
$("input").focus(function () { that=this;
$(this).parent(".drop").css("display", "block");
$(this).blur(function() {
$(that).parent(".drop").css("display", "none");
});
})
You can take a look at an example here: http://jsfiddle.net/WBrns/12/
If a user begins to type, the drop down should not disappear even if they move their mouse away. However, if they click outside of the drop down, it will be hidden.
To improve upon Shaz's answer, you can name the blur event to prevent multiple blur events from being attached to the same input. I also recommend using a class name and CSS to show and hide the drop down so that you can take advantage of CSS transitions.
JS
$('input').focus(function () {
var $this = $(this);
var $drop = $this.parents('.drop');
$drop.addClass('open');
$this.bind('blur.closeDrop', function () {
$drop.removeClass('open');
$this.unbind('blur.closeDrop');
});
});
CSS
.drop {
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}
.drop.open {
opacity: 1;
pointer-events: auto;
}
In my ASP.net page, which does have scroll bar, I have placed a customized control in which I have used a HTML check box (it's like hierarchical structure).
When I scroll down the page (to reach to that control) and then I select any item from that check box, the page scrolls up to the top of the page, without causing post back.
How can I stop the scrolling issue from happening?
Note: It only happens with Firefox, it doesn't happens on other browsers i.e IE 8/9 & Chrome.
This is my customized control, which I have used in My another asp.net page,is when i check any of the bellow items. it causes scroll up of page.
<asp:Panel ID="TreeViewPanel" runat="server" style="border: 1px solid #CCC; width: 210px; padding:5px 0;">
<ul id="tree">
<li>
<label>
<input type="checkbox" value="treeHdrCheck1" runat="server"/>Win Exe
</label>
<ul>
<li>
<label>
<input type="checkbox" value="1" runat="server"/>.EXE</label></li>
<li>
<label>
<input type="checkbox" value="2" runat="server"/>.DLL</label></li>
<li>
<label>
<input type="checkbox" value="3" runat="server"/>.OCX</label></li>
<li>
<label>
<input type="checkbox" value="4" runat="server"/>.SYS</label></li>
<li>
<label>
<input type="checkbox" value="5" runat="server"/>.SCR</label></li>
</ul>
</li>
Are you styling your checkboxes?
If you use CSS like
label {
display: block;
overflow: hidden;
}
label input[type="checkbox"] {
position: absolute;
left: -10000px;
top: -10000px;
}
to hide the actual input element from the containing label, then you may need to remove the top: -10000px; part, because Firefox seems to be wanting to scroll the input element into view.
Like a lot of people, I'd like to customize the ugly input type=file, and I know that it can't be done without some hacks and/or javascript. But, the thing is that in my case the upload file buttons are just for uploading images (jpeg|jpg|png|gif), so I was wondering if I could use a "clickable" image which would act exactly as an input type file (show the dialog box, and same $_FILE on submitted page).
I found some workaround here, and this interesting one too (but does not work on Chrome =/).
What do you guys do when you want to add some style to your file buttons? If you have any point of view about it, just hit the answer button ;)
This works really well for me:
.image-upload>input {
display: none;
}
<div class="image-upload">
<label for="file-input">
<img src="https://icons.iconarchive.com/icons/dtafalonso/android-lollipop/128/Downloads-icon.png"/>
</label>
<input id="file-input" type="file" />
</div>
Basically the for attribute of the label makes it so that clicking the label is the same as clicking the specified input.
Also, the display property set to none makes it so that the file input isn't rendered at all, hiding it nice and clean.
Tested in Chrome but according to the web should work on all major browsers. :)
EDIT:
Added JSFiddle here: https://jsfiddle.net/c5s42vdz/
Actually it can be done in pure css and it's pretty easy...
HTML Code
<label class="filebutton">
Browse For File!
<span><input type="file" id="myfile" name="myfile"></span>
</label>
CSS Styles
label.filebutton {
width:120px;
height:40px;
overflow:hidden;
position:relative;
background-color:#ccc;
}
label span input {
z-index: 999;
line-height: 0;
font-size: 50px;
position: absolute;
top: -2px;
left: -700px;
opacity: 0;
filter: alpha(opacity = 0);
-ms-filter: "alpha(opacity=0)";
cursor: pointer;
_cursor: hand;
margin: 0;
padding:0;
}
The idea is to position the input absolutely inside your label. set the font size of the input to something large, which will increase the size of the "browse" button. It then takes some trial and error using the negative left / top properties to position the input browse button behind your label.
When positioning the button, set the alpha to 1. When you've finished set it back to 0 (so you can see what you're doing!)
Make sure you test across browsers because they'll all render the input button a slightly different size.
Great solution by #hardsetting,
But I made some improvements to make it work with Safari(5.1.7) in windows
.image-upload > input {
visibility:hidden;
width:0;
height:0
}
<div class="image-upload">
<label for="file-input">
<img src="https://via.placeholder.com/300x300.png?text=UPLOAD" style="pointer-events: none"/>
</label>
<input id="file-input" type="file" />
</div>
I have used visibility: hidden, width:0 instead of display: none for safari issue and added pointer-events: none in img tag to make it working if input file type tag is in FORM tag.
Seems working for me in all major browsers.
Hope it helps someone.
A much better way than writing JS is to use native,
and it turns to be lighter than what was suggested:
<label>
<img src="my-image.png">
<input type="file" name="myfile" style="display:none">
</label>
This way the label is automatically connected to the input that is hidden.
Clicking on the label is like clicking on the field.
You can replace image automatically with newly selected image.
<div class="image-upload">
<label for="file-input">
<img id="previewImg" src="https://icon-library.net/images/upload-photo-icon/upload-photo-icon-21.jpg" style="width: 100px; height: 100px;" />
</label>
<input id="file-input" type="file" onchange="previewFile(this);" style="display: none;" />
</div>
<script>
function previewFile(input){
var file = $("input[type=file]").get(0).files[0];
if(file){
var reader = new FileReader();
reader.onload = function(){
$("#previewImg").attr("src", reader.result);
}
reader.readAsDataURL(file);
}
}
</script>
I would use SWFUpload or Uploadify. They need Flash but do everything you want without troubles.
Any <input type="file"> based workaround that tries to trigger the "open file" dialog by means other than clicking on the actual control could be removed from browsers for security reasons at any time. (I think in the current versions of FF and IE, it is not possible any more to trigger that event programmatically.)
This is my method if i got your point
HTML
<label for="FileInput">
<img src="tools/img/upload2.png" style="cursor:pointer" onmouseover="this.src='tools/img/upload.png'" onmouseout="this.src='tools/img/upload2.png'" alt="Injaz Msila" style="float:right;margin:7px" />
</label>
<form action="upload.php">
<input type="file" id="FileInput" style="cursor: pointer; display: none"/>
<input type="submit" id="Up" style="display: none;" />
</form>
jQuery
<script type="text/javascript">
$( "#FileInput" ).change(function() {
$( "#Up" ).click();
});
</script>
I have had lots of issues with hidden and not visible inputs over the past decade sometimes things are way simpler than we think.
I have had a little wish with IE 5,6,7,8 and 9 for not supporting the opacity and thus the file input would cover the upload image however the following css code has resolved the issue.
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
The following snipped is tested on chrome, IE 5,6,7,8,9,10 the only issue in IE 5 is that it does not support auto margin.
Run the snippet simply copy and paste the CSS and HTML modify the size as you like.
.file-upload{
height:100px;
width:100px;
margin:40px auto;
border:1px solid #f0c0d0;
border-radius:100px;
overflow:hidden;
position:relative;
}
.file-upload input{
position:absolute;
height:400px;
width:400px;
left:-200px;
top:-200px;
background:transparent;
opacity:0;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
.file-upload img{
height:70px;
width:70px;
margin:15px;
}
<div class="file-upload">
<!--place upload image/icon first !-->
<img src="https://i.stack.imgur.com/dy62M.png" />
<!--place input file last !-->
<input type="file" name="somename" />
</div>
its really simple you can try this:
$("#image id").click(function(){
$("#input id").click();
});
You can put an image instead, and do it like this:
HTML:
<img src="/images/uploadButton.png" id="upfile1" style="cursor:pointer" />
<input type="file" id="file1" name="file1" style="display:none" />
JQuery:
$("#upfile1").click(function () {
$("#file1").trigger('click');
});
CAVEAT:
In IE9 and IE10 if you trigger the onclick in a file input via javascript the form gets flagged as 'dangerous' and cannot be submmited with javascript, no sure if it can be submitted traditionaly.
The input itself is hidden with CSS visibility:hidden.
Then you can have whatever element you whish - anchor or image.., when the anchor/image is clicked, trigger a click on the hidden input field - the dialog box for selecting a file will appear.
EDIT: Actually it works in Chrome and Safari, I just noticed that is not the case in FF4Beta
Working Code:
just hide input part and do like this.
<div class="ImageUpload">
<label for="FileInput">
<img src="../../img/Upload_Panel.png" style="width: 18px; margin-top: -316px; margin-left: 900px;"/>
</label>
<input id="FileInput" type="file" onchange="readURL(this,'Picture')" style="cursor: pointer; display: none"/>
</div>
form input[type="file"] {
display: none;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Simple File Upload</title>
<meta name="" content="">
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<label for="fileToUpload">
<img src="http://s3.postimg.org/mjzvuzi5b/uploader_image.png" />
</label>
<input type="File" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
RUN SNIPPET or Just copy the above code and execute. You will get what you wanted. Very simple and effective without javascript. Enjoy!!!
<script type="text/javascript">
function upl() {
var fileSelector = document.createElement('input');
fileSelector.setAttribute('type', 'file');
fileSelector.setAttribute('name', 'uploimg');
fileSelector.setAttribute('accept', 'image/*');
fileSelector.click();
fileSelector.style.display = "none";
fileSelector.onchange = function() {
document.getElementById("indicator").innerHTML = "Uploaded";
};
document.getElementById("par_form").appendChild(fileSelector);
}
</script>
<form id="par_form">
<img src="image_url" onclick="upl()"><br>
<span id="indicator"></span><br>
<input type="submit">
</form>