how to remove hint when someone inputs in text input - javascript - javascript

I have a this text input
<input id="searchInput" type="text" value="Search Here" />
I want to remove the value of the input i.e. 'Search Here' as someone enters something ...
How to do this in jQuery or in javascript ?

Simply use placeholder text
<input id="searchInput" type="text" placeholder="Search Here" />
http://www.w3.org/TR/html5/forms.html#the-placeholder-attribute

If the browser provides HTML5 capabilities you could simply use the placeholder attribute.
However, if the user agent doesn't provide HTML5 capabilities you can use onfocus and onblur.

Since you say jQuery, jquery-watermark is a good plugin.
It will add a watermark regardless of the browser capabilities.
It will use a placeholder if the browser supports it, and fallback to creating dom elements on browsers that don't
$('#searchInput').watermark('Search Here');

You can use Placeholder for your code.
<input id="searchInput" type="text" placeholder="Search Here" />
Here's a workind fiddle

Related

Is there a way to disable chrome autofill option for angular form fields

I have tried using autocomplete false and also auto complete off. The cache is removed from the field, but iam still seeing chrome autofill data. Is there a way to disable chrome autofill option in angular forms? Any suggestions would be appreciated. Thanks
Please check the autocomplete="new-password":
<input type="password" name="password" value="" autocomplete="new-password" />
It worked for me. Found in Google documentation
The autocomplete="off" is effectively respected by Chrome, but what you're experiencing is the Chrome autofill functionality that takes over, ignoring autocomplete="off": https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill.
In the past, many developers would add autocomplete="off" to their form fields to prevent the browser from performing any kind of autocomplete functionality. While Chrome will still respect this tag for autocomplete data, it will not respect it for autofill data.
One workaround is to put an unknown value in the autocomplete, e.g. <input type="text" name="somethingAutofillDoesntKnow" autocomplete="doNotAutoComplete" />. When testing this it worked for me most of the time, but for some reason didn't work anymore afterwards.
My advise is not to fight against it and use it's potential by properly using the autocomplete attribute as explained here: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill
Through some trial and error testing, it appears that if you set the input name and autocomplete attributes to a random string, Chrome's autofill is prevented from appearing. I created a small directive to achieve this.
import { Directive, ElementRef, Renderer2, AfterViewInit } from '#angular/core';
#Directive({
selector: '[appDisableAutofill]'
})
export class DiableAutofillDirective implements AfterViewInit {
constructor(private readonly el: ElementRef, private readonly renderer: Renderer2) { }
ngAfterViewInit() {
const randomString = Math.random().toString(36).slice(-6);
this.renderer.setAttribute(this.el.nativeElement, 'name', randomString);
this.renderer.setAttribute(this.el.nativeElement, 'autocomplete', randomString);
}
}
Just change your input from type TEXT to type SEARCH.
<input type="search" name="your_address" autocomplete="nope" />
Chrome fill work with text fields but it's ignored on search type.
Chrome seems to ignore all practical/clean attempts to stop this - so we need to get a little hacky. I prevented this using 2 honeypot inputs. They can NOT be "display:none" or they will get skipped. So I wrapped them in a div that's height:0; overflow:hidden; and gave them opacity 0 (just to be double sure). Your real inputs must come AFTER the honeypots. See below
<!-- honeypot prevents chrome user autofill bs-->
<div style="height:0; overflow:hidden">
<input style="opacity:0;" type="email" value="" class="" />
<input style="opacity:0;" type="password" value="" class="d-" />
</div>
<!-- end honeypot -->
<!-- ... then put your real inputs after-->
<input type="email" name="email" value="" class="" />
<input type="password" name="password" value="" class="d-" />
<!-- end honeypot -->
Disabling autocompletion
To disable autocompletion in forms, you can set the autocomplete attribute to "off":
You can do this either for an entire form, or for specific input elements in a form:
<form [formGroup]="exampleForm" autocomplete="off">
...
</form>
// or
<form [formGroup]="exampleForm">
<div>
<label >Credit card:</label>
<input type="text" id="cc" name="cc" autocomplete="off">
</div>
</form>
To Disable in Login Fields:
many modern browsers do not support autocomplete="off" for login fields:
to prevent autofilling of password fields, you can use
autocomplete="new-password"
I had similar issue, I was not able to resolved it with any of the solution maybe because I was using third party for Google places Autocomplete ngx-google-places-autocomplete
where autofill overlapping google suggested address. I was able to resolve it using focus event as shown below
<input ngx-google-places-autocomplete [options]='options' #placesRef="ngx-places" (onAddressChange)="handleAddressChange($event)"
type="text" class="form-control" id="address1"
formControlName="address1" placeholder="Street address, P.O. box" required (focus)="setAutoFillOff($event)">
setAutoFillOff(event: any) {
if (event) {
event.target.attributes['autocomplete'].value = 'chrome-off';
}
}
I am putting out this to helps who might be in similar situation.
It appears that autocomplete="off" can be used directly on form tag.
Useful when you have a lot of text inputs
<form [formGroup]="vmForm" autocomplete="off">
Google Chrome Version 78.0.3904.108
TLDR; Don't label your inputs with obvious names or Chrome will pick that up and autofill the input.
I often use a form-group class to wrap my labels and inputs together, pretty common practice. So much so the only way I found to get around AutoFill in Chrome (Angular 8, Chrome v80) was to change the value of my label for the input.
Turns Off AutoFill:
<div class="form-group">
<label for="aRandomPlace" class="form-group-label">Pickup Location</label>
<input type="text" name="aRandomPlace" [(ngModel)]="data.address" class="form-group-input">
</div>
Does Not Turn Off AutoFill:
<div class="form-group">
<label for="address" class="form-group-label">Pickup Address</label>
<input type="text" name="address" [(ngModel)]="data.address" class="form-group-input">
</div>
I believe we are discussing to disable 'autosuggestions' not 'autocomplete'
"Autocomplete=off" works for the text type input field but the browser ignores it if it is password type. there are lot many suggestions to use "Autocomplete='chrome-off', 'new-password'" but these are not meant to disable autosuggestions.
for these, I prefer masking technique to mask the content.
.autocompleteOff{
-webkit-text-security: disc;
}
<input class='autocompleteOff' type=text>
Just add to all the HTML input tag which is being auto filled within a form tag as bellow:
<input type="text" class="form-control" id="inputId"
name="inputName" autocomplete="new-inputName"
[(ngModel)]="model">
Note: Use "new-form_element_name" as autocomplete property as shown above.
It worked for me!!!
I found the answer in documentation and it works like a charm.
You can find more about it here.
<input type="text" autocomplete="off" name="one-time-code" id="one-time-code">
Usually what I do is I change type of input dynamically for example in Angular:
[type]="(field.length > 0)? 'password' : 'text'"
In this manner, the browser is unable to recognise the password field the first time you click it and will not provide a suggestion. However, if the field value has been input once and then erased, the browser will provide a suggestion. (At least it is not providing suggestion for the first time).

HTML autocorrect for text input is not working

I am trying to perform some autocorrect for English words in text input. Here is my code:
<input autocomplete="on" autocorrect="on" autocapitalize="on" type="text" name="textinput" placeholder="Enter a test" spellcheck="on">
My JSFiddle
However, it does not seems to work on Chrome by using a desktop computer. Is this feature only applicable for mobile?
Try using spellcheck="true" html attribute instead of autocorrect="on"
<input autocomplete="on" spellcheck="true" autocapitalize="on" type="text" name="textinput" placeholder="Enter a test" spellcheck="on">
autocorrect="on" is currently a non-standard attribute.
This is a non-standard attribute supported by Safari that is used to
control whether autocorrection should be enabled when the user is
entering/editing the text value of the <input>
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-autocorrect

How can I stop auto capitalization in a html text input field on an android/samsung phone?

I am trying to get all lowercase in a html text input field on a samsung android phone.
Can anyone suggest something else to try to stop the auto capitalization for the first letter in a text field?
I have tried the following and nothing works.
CSS
.my_username{text-transform:lowercase;}
input[type=text] {text-transform:lowercase;}
JS
my_username.setAttribute("autocapitalize","off");
in submitonenter(my_username.value.toLowerCase();)
HTML
input autocapitalize="off" type="text" class="my_username" name="username" size="19" value="" maxlength="19" onkeypress="submitonenter(event,this)"
You need to to say autocapitalize="off" in your markup
Example
<input type="text" autocorrect="off" autocapitalize="off"/>
Click here for more details.
For android phones you have to use autocomplete="off"
So if you want something generic, complete #kumars' answers this way:
<input type="text" autocorrect="off" autocapitalize="none" autocomplete="off"/>
The autocorrect and autocapitalize attributes works on the iPhone or the iPad, autocomplete is for any device running Android.
NB: Use autocapitalize="none" instead of autocapitalize="off" because "off" is deprecated for autocapitalize. See official documentation.
If you are also using React, use autoCapitalize="none".

Show/Hide previous form field entries

I was wondering if someone knows what controls the showing of previous form field entries in a form.
So for example, if in the name field, I go to type 'John' it appears below the field. Is that a feature of the browser or is it javascript or something?
Also, if it is the browser, is there a way I can turn this off for a given form?
You might be looking at autocomplete, if so turn it off with autocomplete="off" within the HTML of the relevant field:
<input type="text" name="firstname" autocomplete="off" />
References:
input element.
It's made by the browser, if you're working with HTML5 you can set a attribute to the input-element to remove it.
<input type="text" autocomplete="off" />

INPUT TEXT remove browser default dropdown

how can i remove the focusin dropdown that you see in this image?
by css or javascript? How?
thanks.
Use autocomplete="off":
<input type="text" autocomplete="off">
However, this is a non-standard attribute for HTML version < 5. In HTML5 you can freely use this attribute, see the reference:
http://www.w3.org/TR/html5/the-form-element.html#attr-form-autocomplete
If that's input of type text then you can do it by specifying attribute autocomplete:
<input type="text" autocomplete="off"/>
Attribute for <INPUT ...>
AUTOCOMPLETE = ON | OFF
<input type="text" autocomplete="off">
Good read
How to Turn Off Form Autocompletion

Categories

Resources