Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when hitting enter when attached to form control #351

Closed
carlhussey opened this issue Mar 8, 2019 · 21 comments
Closed

Error when hitting enter when attached to form control #351

carlhussey opened this issue Mar 8, 2019 · 21 comments

Comments

@carlhussey
Copy link

I am using a very basic editor attached to a form control. I see the editor and the toolbar and the buttons work within it.

As soon as I hit enter within the editor, I get the following error to the console.

onloadwff.js:71 Assertion failed: Input argument is not an HTMLInputElement
getFormProfile @ onloadwff.js:71
setFieldValue @ onloadwff.js:71
formKeydownListener @ onloadwff.js:71
onloadwff.js:71 Uncaught TypeError: Cannot read property 'type' of undefined
    at e.setFieldValue (onloadwff.js:71)
    at HTMLFormElement.formKeydownListener (onloadwff.js:71)

I dont have my own example but I was looking at another page that has different setups for the editor and I get the same issue on theirs.

https://killercodemonkey.github.io/ngx-quill-example/

If you type in the "Reactive Forms and Path Value" editor and just hit enter, it should throw the error.

@KillerCodeMonkey
Copy link
Owner

KillerCodeMonkey commented Mar 8, 2019

do you use some browser addons?
I do not know that script:
onloadwff.js:71

Do you using the chrome LastPass Plugin?
vuejs/vue-cli#236 (comment)

And when i am using my example there is no error (tested in ff, chrome and safari):

bildschirmfoto 2019-03-08 um 07 02 52

@dcsan
Copy link

dcsan commented Mar 14, 2019

this is lastPass POS

@mnahkies
Copy link

Does anyone know of a general workaround for this? (aside from disabling lastpass)

@dangxuanphuc
Copy link

I fixed this error by right click on the extension, then select "This Can Read and Change Site Data". Then select "When You Click the Extension".

@KillerCodeMonkey
Copy link
Owner

@dangxuanphuc thanks for your Info. I think this will help a lot of people :)

@mnahkies
Copy link

@dangxuanphuc I actually meant workaround from the development side - I've ended up solving this in my project by stopping keypress event propagation on the affected form. (event.stopPropagation())

Can't see any similar event handlers in the ngx-quill codebase, so would probably need something similar done in quill itself to prevent it.

@KillerCodeMonkey
Copy link
Owner

KillerCodeMonkey commented Mar 22, 2019 via email

@mnahkies
Copy link

@KillerCodeMonkey my form looks something like:

      <form ngForm [formGroup]="myFormGroup" autocomplete="off">
        <mat-form-field color="accent">
          <textarea matInput matTextareaAutosize
            formControlName="content"
            placeholder="something"
            (keydown.enter)="textareaEnterPressed($event)"
          ></textarea>
        </mat-form-field>
      </form>

With the event handler looking like:

textareaEnterPressed($event: KeyboardEvent): boolean {
    $event.preventDefault()
    $event.stopPropagation()

    // handle form submission
  }

I haven't spent any time understanding why the last pass extension is throwing an exception if I let it receive this event, but preventing it from getting the event with $event.stopPropagation() has solved the ugly error in the console, and fits with my use case fine. Also haven't worked out where the extension is attaching the event listener

@johnjcamilleri
Copy link

If you don't have any extra logic to add and just want to shut up LastPass without disabling it, you can even just do this:

<form>
 <textarea v-on:keydown.enter="$event.stopPropagation()">...</textarea>
</form>

@j-berman
Copy link

j-berman commented Jul 12, 2019

Above fixes weren't working for me with React, but I got it working by adding my own event listener to the DOM

My form looks like this:

<form>
  <input
    name='my-input'
    type='text'
    value={myInput}
    onClick={this.handleChangeInput}
  />

  <input
    type='submit'
    onClick={this.handleSubmit}
  />
</form>

Adding the following to my component worked:

componentWillMount () {
  document.addEventListener('keydown', this.handleHitEnter, true)
}

componentWillUnmount() {
  document.removeEventListener('keydown', this.handleHitEnter, true)
}

handleHitEnter(e) {
  const ENTER_KEY_CODE = 13
  if (e.target.name === 'my-input' &&
     (e.key === 'Enter' || e.keyCode === ENTER_KEY_CODE)) {
      e.stopPropagation()
  }
}

handleChangeInput(e) {
  this.setState({ myInput: e.target.value })
}

handleSubmit(e) {
  // e.stopPropagation() // doesn't work because LastPass handles the keydown event first before propagating to this handler
  
  ... code to handle form submission ...
}

I tried adding lots of different handlers in different spots in my form, but nothing worked because LastPass would handle the keydown event first before propagating to any handlers I would write (rather than the other way around as I think must be the case with you guys^). I'm not sure why this was happening with React

Edit: also sorry for including the above in this repo -- I know it doesn't really apply to ngx-quill. I found this issue via a google search and the explanations for the issue above were the best I found around the web. So leaving this here for anyone else who may stumble across it like me

@KillerCodeMonkey
Copy link
Owner

KillerCodeMonkey commented Jul 12, 2019 via email

@j-berman
Copy link

@KillerCodeMonkey haha ya I realized, see my edit. The issue is universal though and affects everyone regardless of frontend framework. The (really good) explanations provided above apply to React too albeit with the minor difference I mentioned. I think there's a solid chance others using React have come across this git issue by google searching like me -- it's the best one I came across that helped me understand the issue

@gegorov
Copy link

gegorov commented Oct 3, 2019

@KillerCodeMonkey, @j-berman it doesn't matter. react or angular, it is Web API. In my case using event.stopPropagation() didn't solve the problem.
But at the same time stopImmidiatePropagation() worked perfectly. it looks like that lastPass is setting listeners on the same level. and we need to avoid other listeners to be called. more about stopImmidiatePropagation on MDN

@kroyee
Copy link

kroyee commented Nov 20, 2019

I got this same issue while using react-bootstrap. Adding an empty type to the Form element solved it for me.

<Form type=""> ... </Form>

@shayneoneill
Copy link

For what its worth, I'm getting this same error in the ractive.js framework. So I don't think its anything you guys specifically are doing.

@KillerCodeMonkey
Copy link
Owner

KillerCodeMonkey commented Jan 25, 2020 via email

@mariordev
Copy link

mariordev commented Mar 3, 2020

Does anyone know of a general workaround for this? (aside from disabling lastpass)

Here's a workaround I found:

  1. Assign an id to the form.
  2. Move all form input elements and button(s) so that they are outside of the form element.
  3. Use the form attribute on all form field elements. This lets you associate fields with the form, without requiring the fields to be inside the form element.

Like so:

<form id="form-user-edit"></form>

<input type="text" name="first_name" form="form-user-edit">
<button type="submit" form="form-user-edit">Submit</button>

It looks a bit funny having form elements outside the form, but it is valid markup, and it's a workaround to this issue. Lastpass should really fix this issue though.

More info: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefform

@bwilson
Copy link

bwilson commented Jun 8, 2020

Thanks @mariordev, that worked for me!

@shayneoneill
Copy link

This really needs to be something Lastpass fixes since it seems to be the cause of this in multiple frameworks :/ Because yeah you can stick your fields outside a form, but its not very hygenic.

@mariordev
Copy link

Yeah, @shayneoneill, I completely agree. Lastpass should definitely own up to it and fix this issue. This is not an ideal solution, but simply a workaround (as someone asked if there was a general workaround, and this is one that I found).

@thalaeg
Copy link

thalaeg commented Feb 23, 2021

You can likely add data-lpignore="true" to your form element.. so

<form data-lpignore="true"> 
  ... 
</form>

Check out this stack overflow thread for info on ignoring last pass stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests