Skip to content

Commit

Permalink
feat(input): permite output através do (p-change-model)
Browse files Browse the repository at this point in the history
Permite emissão de evento com `(p-change-model)` após resetar formulário reativo

Modificação feita por conta de um bug que impedia a emissão do evento após resetar o formulário reativo no Angular.

angular/angular#54022
angular/angular#52135
angular/angular#50971
angular/angular#46458
angular/angular#15741

Fixes DTHFUI-7232
  • Loading branch information
anliben committed Mar 4, 2024
1 parent 7e263a8 commit fc87c02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ describe('PoInputBase:', () => {
it('controlChangeModelEmitter: should not emit changeModel if previous model value is equal to current model value', () => {
const newModelValue: number = 1;
component.modelLastUpdate = 1;
component.emitAllChanges = false;

spyOn(component.changeModel, 'emit');
component.controlChangeModelEmitter.call(component, newModelValue);
Expand All @@ -237,9 +238,10 @@ describe('PoInputBase:', () => {
});

it(`controlChangeModelEmitter: should emit changeModel with new value if previous
model value is different from current model value`, () => {
model value is different from current model value`, () => {
const newModelValue: number = 2;
component.modelLastUpdate = 1;
component.emitAllChanges = true;

spyOn(component.changeModel, 'emit');
component.controlChangeModelEmitter.call(component, newModelValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ export abstract class PoInputBaseComponent implements ControlValueAccessor, Vali
*/
@Input('p-icon') icon?: string | TemplateRef<void>;

/**
* @optional
*
* @description
*
* Sempre emite as alterações do model mesmo quando o valor atual for igual ao valor anterior.
*
* @default `false`
*/
@Input({ alias: 'p-emit-all-changes', transform: convertToBoolean }) emitAllChanges: boolean = false;

/** Rótulo do campo. */
@Input('p-label') label?: string;

Expand Down Expand Up @@ -358,7 +369,7 @@ export abstract class PoInputBaseComponent implements ControlValueAccessor, Vali
}

controlChangeModelEmitter(value: any) {
if (this.modelLastUpdate !== value) {
if (this.modelLastUpdate !== value || this.emitAllChanges) {
this.changeModel.emit(value);
this.modelLastUpdate = value;
}
Expand Down

0 comments on commit fc87c02

Please sign in to comment.