Skip to content

chore(*): Sync editValue changes with the formControl value and mark … #12076

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

Merged
merged 25 commits into from
Oct 26, 2022

Conversation

MayaKirova
Copy link
Contributor

@MayaKirova MayaKirova commented Sep 13, 2022

…as touched for better custom template handling.

Closes #12066

Additional information (check all that apply):

  • Bug fix
  • New functionality
  • Documentation
  • Demos
  • CI/CD

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
erezrokah Erez Rokah
…as touched for better custom template handling.
MKirova added 2 commits September 13, 2022 16:24

Verified

This commit was signed with the committer’s verified signature.
erezrokah Erez Rokah

Verified

This commit was signed with the committer’s verified signature.
erezrokah Erez Rokah
@MayaKirova MayaKirova added grid: general ❌ status: awaiting-test PRs awaiting manual verification labels Sep 13, 2022
@MayaKirova MayaKirova marked this pull request as ready for review September 13, 2022 14:39
@dkamburov dkamburov changed the base branch from master to 14.1.x September 14, 2022 06:49
@@ -870,7 +870,6 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
// while in edit mode subscribe to value changes on the current form control and set to editValue
this.formControl.valueChanges.pipe(takeWhile(x => this.editMode)).subscribe(value => {
this.editValue = value;
Copy link
Member

Choose a reason for hiding this comment

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

If this being a setter also goes and sets the value right back to the form control, wouldn't it sort of double dip with the validation logic? Wondering if we could use the form control as the backing for editValue entirely (assuming getting it from the service is quick), which might allow us to even skip this sync sub?

Copy link
Member

@damyanpetev damyanpetev left a comment

Choose a reason for hiding this comment

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

Minor comments, of which only the getter is of some importance.

We should still leave an explanation in the docs that using the [formControl] directive to bind edit templates in combination with blur trigger will leave the cell editValue unsynced until blur/edit exit due to the way the form control handles its value.

@@ -97,10 +97,30 @@ export class IgxCell {
public rowIndex: number,
public column,
public value: any,
public editValue: any,
public _editValue: any,
Copy link
Member

Choose a reason for hiding this comment

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

Assuming IgxCell is internal (fairly certain it is), I guess this can remain public too. Could've been done with an extra method to assign the value too.

public rowData: any,
public grid: GridType) {
this.grid.validation.create(id.rowID, rowData);
this.editValue = this._editValue;
Copy link
Member

Choose a reason for hiding this comment

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

This will likely trigger an extra validation, though I think I saw the public API creating this with different value/editValue initially, so we might be stuck with this.

const formControl = this.grid.validation.getFormControl(this.id.rowID, this.column.field);
if (formControl) {
return formControl.value;
}
Copy link
Member

Choose a reason for hiding this comment

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

Kind of surprised, this doesn't break the model bind with blur if the value changes, yet the getter still returns the old one. It works, but still perhaps it'd be better if we return the pending value for blur for consistency?

@skrustev skrustev added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification labels Sep 19, 2022
@skrustev
Copy link
Member

Thee only thing I found s that an error is throw when validationTrigger is set to change only and adding row
Steps:

  1. Click on add row
  2. Focus a cell with templated editor
  3. Observe the console log

@skrustev skrustev added ✅ status: verified Applies to PRs that have passed manual verification and removed 💥 status: in-test PRs currently being tested labels Sep 26, 2022
georgianastasov and others added 2 commits September 27, 2022 12:47
* fix(excel-exporter): export correct number of rows#12086

* fix(excel-exporter): fix total rowCount with multi col headers#12086

* fix(excel-exporter): fix spacing#12086

constructor(
public id,
public rowIndex: number,
public column,
public value: any,
public editValue: any,
public _editValue: any,
public rowData: any,
public grid: GridType) {
this.grid.validation.create(id.rowID, rowData);
Copy link
Member

Choose a reason for hiding this comment

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

@MayaKirova There's one odd case where the grid public updateCell API creates a new IgxCell with a different edit value and the form control will be out of sync here. That's actually not new it seems, however, with these changes the so will be the new value used by the API call (it just uses the args) to perform the update.
That's fortunately for blur only and could be logged separately, if we consider it still a minor use, though it's API that should work regardless.
Ideally, we'd initialize the form control with the edit value regardless instead of setting it additionally.

@MayaKirova MayaKirova added ❌ status: awaiting-test PRs awaiting manual verification and removed ✅ status: verified Applies to PRs that have passed manual verification labels Sep 29, 2022
Comment on lines 34 to +35
const control = new FormControl(value, { updateOn: this.grid.validationTrigger });
control.setValue(value);
Copy link
Member

Choose a reason for hiding this comment

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

Um.. if the control was just initialized with the same value, I'm kind of missing the point of assigning it again. Any specific reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It's due to a rather weird behavior when the initial value is undefined (which we use when creating an adding row for example, all fields have undefined as value). When the form control is created for undefined it actually sets it to null instead:

So this:

new FormControl(undefined, { updateOn: this.grid.validationTrigger });

Then returns null for control.value.

Which breaks some tests.

@ChronosSF ChronosSF requested a review from damyanpetev October 10, 2022 08:07
@ChronosSF ChronosSF changed the base branch from 14.1.x to 14.2.x October 10, 2022 08:08
@skrustev skrustev added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification labels Oct 14, 2022
@skrustev skrustev added ✅ status: verified Applies to PRs that have passed manual verification and removed 💥 status: in-test PRs currently being tested labels Oct 18, 2022
@dkamburov dkamburov merged commit 64fff25 into 14.2.x Oct 26, 2022
@dkamburov dkamburov deleted the mkirova/editValue-formControl-auto-sync branch October 26, 2022 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grid: general version: 14.2.x ✅ status: verified Applies to PRs that have passed manual verification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for cell edit templates binding editValue to function fully with validation
6 participants