Skip to content
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

ng-dirty class gets added when i change my custom component value programmatically #25738

Closed
kumaresan-subramani opened this issue Aug 30, 2018 · 9 comments
Labels
needs reproduction This issue needs a reproduction in order for the team to investigate further

Comments

@kumaresan-subramani
Copy link

I'm submitting a...

Bug report

If i change value of my custom component programmatically ng-dirty class gets added but it is not the behavior. here i have added my stackblitz sample [ https://stackblitz.com/edit/angular-5gjp4o?file=src/app/app.component.html ]

Current behavior

-ng-dirty class gets adding

Expected behavior

-ng-dirty will not be added

Minimal reproduction of the problem with instructions

stackblitz sample [ https://stackblitz.com/edit/angular-5gjp4o?file=src/app/app.component.html ]

1.open this sample
2.run and then click button whichis appended to the sample then you will see the dirty class getting added

What is the motivation / use case for changing the behavior?

it doesn't match to behavior

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

@trotyl
Copy link
Contributor

trotyl commented Aug 30, 2018

It's the problem of your library, please report the issue there.

@kumaresan-subramani
Copy link
Author

no.... if i use any custom component, this error comes

@pkozlowski-opensource
Copy link
Member

@kumaresan-subramani please provide a minimal reproduce scenario without any 3rd-party dependencies - we need to have angular-only stackblitz to be able to confirm an issue in the framework.

@pkozlowski-opensource pkozlowski-opensource added the needs reproduction This issue needs a reproduction in order for the team to investigate further label Aug 30, 2018
@kumaresan-subramani
Copy link
Author

OKay @pkozlowski-opensource

@trotyl
Copy link
Contributor

trotyl commented Aug 30, 2018

@kumaresan-subramani Any form control is powered by ControlValueAccessor, there's no difference in built-in or custom ControlValueAccessors, all of them are just normal library code.

@kumaresan-subramani
Copy link
Author

@trotyl ,

okay, now i can understand.

This is my library code, how can i make my component to pristine state when programmaticaly value changed, please prvide any idea?

`import { getValue, setValue, isNullOrUndefined } from '@syncfusion/ej2-base';
/**

  • Angular Form Base Module
    /
    var FormBase = /
    * @Class */ (function () {
    function FormBase() {
    }
    FormBase.prototype.propagateChange = function (_) { return; };
    FormBase.prototype.propagateTouch = function () { return; };

I tried like this
// FormBase.prototype.ngOnInit = function () {
// var self = this;
// var origFunc = this.control.markAsPristine;
// this.control.markAsPristine = function () {
// origFunc.apply(this, arguments);
// console.log('Marked as pristine!');
// };
// };
end
FormBase.prototype.localChange = function (e) {
var value = (e.checked === undefined ? e.value : e.checked);
if (this.propagateChange !== undefined && value !== undefined) {
// Update angular from our control
this.propagateChange(value);
}
};
FormBase.prototype.registerOnChange = function (registerFunction) {
this.propagateChange = registerFunction;
};
FormBase.prototype.registerOnTouched = function (registerFunction) {
this.propagateTouch = registerFunction;
};
FormBase.prototype.twoWaySetter = function (newVal, prop) {
var oldVal = getValue(prop, this.properties);
var ele = this.inputElement || this.element;
if (oldVal === newVal &&
(ele.value === undefined || ele.value === '')) {
return;
}
this.saveChanges(prop, newVal, oldVal);
setValue(prop, (isNullOrUndefined(newVal) ? null : newVal), this.properties);
getValue(prop + 'Change', this).emit(newVal);
};
FormBase.prototype.ngAfterViewInit = function () {
var _this = this;
// Used setTimeout for template binding
// Refer Link: #6005
setTimeout(function () {
/* istanbul ignore else /
if (typeof window !== 'undefined') {
_this.appendTo(_this.element);
var ele = _this.inputElement || _this.element;
ele.addEventListener('focus', _this.ngOnFocus.bind(_this));
ele.addEventListener('blur', _this.ngOnBlur.bind(_this));
}
});
};
FormBase.prototype.setDisabledState = function (disabled) {
this.enabled = !disabled;
};
FormBase.prototype.writeValue = function (value) {
//update control value from angular
if (this.checked === undefined) {
this.value = value;
}
else {
if (typeof value === 'boolean') {
this.checked = value;
}
else {
this.checked = value === this.value;
}
}
if (value === null) {
return;
}
};
FormBase.prototype.ngOnFocus = function (e) {
/
istanbul ignore else /
if (this.skipFromEvent !== true) {
this.focus.emit(e);
}
};
FormBase.prototype.ngOnBlur = function (e) {
this.propagateTouch();
/
istanbul ignore else */
if (this.skipFromEvent !== true) {
this.blur.emit(e);
}
};
return FormBase;
}());
export { FormBase };
`

i have tried like above but "control : Abstractcontrol" is undefined here i can not be able to call "MarkAsPristine()" methoad

@kumaresan-subramani
Copy link
Author

And more thing can you please tell me, where you are generating angular components like if i render input tag , angular will convert it into .
can you please tell where you are converting this [i mean which file? ]

@IgorMinar
Copy link
Contributor

Hello, we reviewed this issue and determined that it doesn't fall into the bug report or feature request category. This issue tracker is not suitable for support requests, please repost your issue on StackOverflow using tag angular.

If you are wondering why we don't resolve support issues via the issue tracker, please check out this explanation.

@angular-automatic-lock-bot
Copy link

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
needs reproduction This issue needs a reproduction in order for the team to investigate further
Projects
None yet
Development

No branches or pull requests

4 participants