How to turn off html input form field suggestions?

前端 未结 8 1370
难免孤独
难免孤独 2021-01-31 07:20

By suggestions I mean the drop down menu appear when you start typing, and it\'s suggestions are based on what you\'ve typed before:

for example when I type \'a

8条回答
  •  难免孤独
    2021-01-31 07:31

    autocomplete = "new-password" does not work for me.

    I built a React Form. Google Chrome will autocomplete the form input based on the name attribute.

     
    

    It will base on the "name" attribute to decide whether to autofill your form. In this example, name: "remark". So Chrome will autofill based on all my previous "remark" inputs.

    
    

    So, to hack this, I give name a random value using uuid() library.

    import uuid from 'react-uuid';
    

    Now, the autocomplete dropdown list will not happen. I use the id attribute to identify the form input instead of name in the handleChange event handler

    handleChange = (event) => {
        const {id, value} = event.target;
        this.setState({
            [id]: value,
        })
    }
    

    And it works for me.

提交回复
热议问题