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.

ng-model-options={updateOn: 'blur'} not working  #7117

Closed
@kyrios

Description

@kyrios

Environment

Version: AngularJS v1.3.0-build.2602+sha.b10a437
Browser: Chrome (OS-X) 34.0.1847.116

Issue description

When using the 'blur' event the value is not saved to the model. Other events and 'default' works fine.

I'd like to use this feature in a ng-grid cell with a custom $parser. After my user enters some text into the cell I want to do one validation run before saving to the model.

I'm new to angular but investigated this a little. Maybe my investigation below helps a little narrowing the issue down.

Maybe it has something to do with event handling order since ng-grid also registers a blur handler.

Investigation

From my understanding ctrl.$setViewValue(value, event) should be called but isn't because of the $apply is a noop. (Line: 17246)

Unfortunately I don't understand the internals of angular enough to understand why $apply is a noop in my case.

if (ctrl.$viewValue !== value ||
        // If the value is still empty/falsy, and there is no `required` error, run validators
        // again. This enables HTML5 constraint validation errors to affect Angular validation
        // even when the first character entered causes an error.
        (validity && value === '' && !validity.valueMissing)) {
      if (scope.$$phase) {
        ctrl.$setViewValue(value, event);   //   <---- Neither this
      } else {
        scope.$apply(function() {
          ctrl.$setViewValue(value, event); //    <---- or this gets called
        });
      }

Plunker

http://plnkr.co/edit/IybN8jtCAdm03sCC2lxg?p=preview
Does this help?

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