Skip to content

feat(forms): support updateOn in ngModelOptions - #18577

Merged
hansl merged 1 commit into
angular:masterfrom
kara:ngModelOptions
Aug 15, 2017
Merged

hansl merged 1 commit into
angular:masterfrom
kara:ngModelOptions

Conversation

@kara

@kara kara commented Aug 8, 2017 •

Copy link
Copy Markdown
Contributor

This commit introduces a new option to template-driven forms that improves performance by delaying form control updates until the "blur" or "submit" event. To use it, set the updateOn property in ngModelOptions.

<input ngModel [ngModelOptions]="{updateOn: 'blur'}">

Like in AngularJS, setting updateOn to 'blur' or 'submit' will delay the update of the value as well as the validation status. Updating value and validity together keeps the system easy to reason about, as the two will always be in sync. It's also worth noting that the value/validation pipeline does still run when the form is initialized (in order to support initial values).

Upcoming PRs will address:

  • Support for setting updateOn at the group level in template-driven forms
  • Option for skipping initial validation run or more global error display configuration
  • Better support of reactive validation strategies

See more context in #18408, #18514, and the design doc.

@mary-poppins

Copy link
Copy Markdown

You can preview 895ccc8 at https://pr18577-895ccc8.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 71470e9 at https://pr18577-71470e9.ngbuilds.io/.

@kara
kara force-pushed the ngModelOptions branch 2 times, most recently from 63664a6 to 321b059 Compare August 8, 2017 05:48
@mary-poppins

Copy link
Copy Markdown

You can preview 63664a6 at https://pr18577-63664a6.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 321b059 at https://pr18577-321b059.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview bc4aba0 at https://pr18577-bc4aba0.ngbuilds.io/.

@kara kara added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 9, 2017
@mary-poppins

Copy link
Copy Markdown

You can preview 3b05d06 at https://pr18577-3b05d06.ngbuilds.io/.

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm for api changes. I didn't review the implementation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the same as in ng_form.ts. Can we reuse the code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point; I'll refactor it to shared.ts

This commit introduces a new option to template-driven forms that
improves performance by delaying form control updates until the
"blur" or "submit" event.  To use it, set the `updateOn` property
in `ngModelOptions`.

```html
<input ngModel [ngModelOptions]="{updateOn: blur}">
```

Like in AngularJS, setting `updateOn` to `blur` or `submit` will
delay the update of the value as well as the validation status.
Updating value and validity together keeps the system easy to reason
about, as the two will always be in sync.  It's also worth noting
that the value/validation pipeline does still run when the form is
initialized (in order to support initial values).

Upcoming PRs will address:

* Support for setting group-level `updateOn` in template-driven forms
* Option for skipping initial validation run or more global error
display configuration
* Better support of reactive validation strategies

See more context in angular#18408, angular#18514, and the [design doc](https://docs.google.com/document/d/1dlJjRXYeuHRygryK0XoFrZNqW86jH4wobftCFyYa1PA/edit#heading=h.r6gn0i8f19wz).

@tinayuangao tinayuangao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kara kara added the action: merge The PR is ready for merge by the caretaker label Aug 10, 2017
@kara kara added target: major This PR is targeted for the next major release and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 10, 2017
@mary-poppins

Copy link
Copy Markdown

You can preview fff5d70 at https://pr18577-fff5d70.ngbuilds.io/.

@hansl
hansl merged commit 1cfa79c into angular:master Aug 15, 2017
kara added a commit to kara/angular that referenced this pull request Aug 16, 2017
This commit introduces a new Input property called
`ngFormOptions` to the `NgForm` directive. You can use it
to set default `updateOn` values for all the form's child
controls. This default will be used unless the child has
already explicitly set its own `updateOn` value in
`ngModelOptions`.

Potential values: `change` | `blur` | `submit`

```html
<form [ngFormOptions]="{updateOn: blur}">
  <input name="one" ngModel>  <!-- will update on blur-->
</form>
```

For more context, see [angular#18577](angular#18577).
hansl pushed a commit that referenced this pull request Aug 16, 2017
This commit introduces a new Input property called
`ngFormOptions` to the `NgForm` directive. You can use it
to set default `updateOn` values for all the form's child
controls. This default will be used unless the child has
already explicitly set its own `updateOn` value in
`ngModelOptions`.

Potential values: `change` | `blur` | `submit`

```html
<form [ngFormOptions]="{updateOn: blur}">
  <input name="one" ngModel>  <!-- will update on blur-->
</form>
```

For more context, see [#18577](#18577).
@shyamal890

shyamal890 commented Oct 13, 2017 •

Copy link
Copy Markdown

This doesn't yet support debounce ngModelOption on inputs. I would like to know what is the logic behind not implementing the same with blur?

Example usecase for debounce:

  • A text input like in Google docs which should save the typed text after 3 secs of no keypress after typing.

@kara
kara deleted the ngModelOptions branch October 13, 2018 01:09
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: forms cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants