Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

angular.element.val() and jquery.val() should call $setViewValue() when necessary #6523

Closed
@benlesh

Description

@benlesh

This issue stems from trying to e2e test HTML5 inputs with protractor.

Problem

WebDriver/Selenium is unable to "sendkeys" to all browsers' implementations of HTML5 controls such as date, time, datetime-local, color, etc. Consequently, these things are hard to test.

Current workaround

Currently in order to set the value of the element with Protractor you need to use browser.executeScript(). For example:

browser.executeScript("document.getElementById('someElem').value = '2011-11-11';");

This does the work of setting the value of the input, however, the way Angular is wiring up validation, the validation will not be fired. This means you also have to manually call $setViewValue() on the model:

var updateInput = "var input = document.getElementById('someInput');" +
    "input.value = '2011-11-11';" + 
    "angular.element(input).scope().$apply(function(s) { s.formName[input.name].$setViewValue(input.value);";
browser.executeScript(updateInput);

... which is, of course, ugly as sin.

Proposed solution

It seems to make sense to have angular.element.val() check to see if the input is part of a form that has a model and force the validation. Likewise, if JQuery is being used, the val() extension could be wrapped to support this behavior. Of course val() should perform as expected on any other input that doesn't have a model bound to it.

Related

angular/protractor#562

#5864

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions