question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clear on input element not updating model

See original GitHub issue

It does not seem like using clear on a input element updates the ngmodel(and triggers validation). The input field is empty in the page but the model hasn’t changed value.

<input [(ngModel)]="model">
<h1>{{model}}</h1>
it('', () => {
    element(by.css('input')).clear()
    expect(element(by.css('h1')).getText()).toEqual('');
  });

Expected ‘app works!’ to equal ‘’.

  • Node Version: 6.10.0
  • Protractor Version: 5.1.1
  • Angular Version: 2.4.9
  • Browser(s): Chrome

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kenborgecommented, Mar 16, 2017

I see your point that the underlying reason the model isn’t updated is the way angular 2 works, and that it doesn’t trigger by the way clear is implemented. However seeing as protractor is a e2e framework for angular applications shouldn’t that make it a protractor issue if parts of its api doesn’t work anymore with core angular 2 mechanics(ngModel)

1reaction
seanmaycommented, Mar 16, 2017

You could make a case for it, as a feature, but then assuming you are calling .clear() on text inputs, and assuming that you can clear it to '', how do you support .clear() on dates, numbers, ranges, colours, et cetera, without introducing some concept of null or undefined or incompatible (or incorrect) assumptions that a program might not have had before, which comes from Protractor making business logic decisions based on your app?

I agree that it’s problematic to have people assume that the full range of all WebDriver APIs is going to implicitly do the right thing in Angular.

I feel like the eventual solution to that is to provide a subset of the APIs, rather than advertising Protractor as Angular-wrapped WebDriver and leaking abstractions which don’t map 1:1 into the Angular view model.

In this case, it would be to remove clear, and force people to set the value through regular UI input interaction methods, rather than to try to intuit what the application really wants there.

Then there are the backwards-compatibility concerns, to ensure that AngularJS and Angular continue to behave appropriately. There is more we can do to ensure that AngularJS and Angular applications each get the APIs they should expect, but that’s a very big and breaking undertaking.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngModel not updating with search input clear button in IE
When using an input type="search" field with AngularJS in IE 9, 10 or 11. When you click the clear / cancel button rendered...
Read more >
Uncontrolled Components - React
To write an uncontrolled component, instead of writing an event handler for every state update, you can use a ref to get form...
Read more >
How to Clear Input Values of Dynamic Form in React
How to clear the values all inputs. At the top of handleReset , use document.querySelectorAll('input') to select all the input elements on the ......
Read more >
<input type="reset"> - HTML: HyperText Markup Language
elements of type reset are rendered as buttons, with a default click event handler that resets all inputs in the form to their...
Read more >
Reset an input field value in React with the update function ...
Simon Vrachliotis: [0:00] Let's implement a quick search reset button to place under the name picker. We only want to show it when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found