Javascript Alert and textbox enter

I am having problem with javascript alert and a textbox listening to enter keypress event. At the form when something is wrong I show user an javascript alert displaying what is wrong, if user press enter key javascript is calling event on textbox too. How can I correct this problem?

Thanks in advance

Patricia

Upvotes: 0

Views: 170

Answers (1)

Tanvi B
Tanvi B

Reputation: 1567

JS code:

   handleChange: function(e) {
        if (e.key == 'Enter') {
           e.preventDefault();
        }

Html code :

     <div>
        <Input type="text"
           ref = "input"
           placeholder="anyText"
           onKeyPress={this.handleChange}
        />
     </div>

Upvotes: 0

Related Questions