Devmix
Devmix

Reputation: 1868

How to disable browser autocomplete on p-inputMask field?

I'm trying to disable browser autocomplete on a field that uses p-inputMask. I can use autocomplete="nope" on any other field and it works great, but it doesn't seem to work on this special case. Can anyone tell me what I'm missing, please? Thanks a lot in advance!

Please attached picture:

Here's my code:

LIVE DEMO

<p-inputMask autocomplete="nope" name="maskValue" mask="(999) 999-9999" placeholder="(999) 999-9999" ></p-inputMask>

NOTE: You will see the browser autocomplete after entering a phone number and clicking on send. I'm trying to get rid of it, but I don't know how.

Upvotes: 1

Views: 8348

Answers (3)

Mesut G&#246;lc&#252;k
Mesut G&#246;lc&#252;k

Reputation: 164

You're giving autocomplete attribute to primeng component.

When I check the primeng source code for p-inputmask I couldn't see an input field for autocomplete. It doesn't bind autcocomplete=off to html input element.

Here you can also check from here

You can open an issue for it.

Also you can try this. Add autocomplete=off to form element

<form autocomplete="off">
   <p-inputMask name="maskValue" mask="(999) 999-9999" placeholder="(999) 999-9999" ></p-inputMask>
   <button type="submit">Send</button>
</form>

Upvotes: 2

sndpkpr
sndpkpr

Reputation: 639

autocomplete="off" can be used in the form, but it will disable autocomplete from the entire form.

<form autocomplete="off">
   <p-inputMask name="maskValue" mask="(999) 999-9999" placeholder="(999) 999-9999" ></p-inputMask>
   <button type="submit">Send</button>
</form>

stackblitz here to disable autocomplete in entire form..

but since it disables autocomplete from the entire form, and if you want that to be done with the single p-inputMask you can use something like this, in a more generic way-

setAttribute('autocomplete', 'off') on AfterViewInit on specific fields.

stackblitz to disable autocomplete only from inputmask

Upvotes: 3

Mihail Stancescu
Mihail Stancescu

Reputation: 4138

Did you try to add to the autocomplete="off", autocomplete="nope" doesn't seem a correct value for the autocomplete attribute. That is the recommend way to disable autocomplete for a field.

This attribute can be added to the form to disable the autocomplete for all fields in the form.

More info on W3s

Upvotes: 0

Related Questions