1

sorry for the question title, can't figure out a better one.

So, i have this function that is triggered by a checkbox true/false value:

setReward(): void {
const rewardControl = this.myFormLost.get('reward');
if (this.lostRewardCheck === true) {
  rewardControl.setValidators(Validators.required);
  rewardControl.enabled  // WHAT GOES HERE
  this.renderer.invokeElementMethod(this.rewardAmountFocus.nativeElement, 'focus', []);
} else {
  rewardControl.clearValidators();
  this.myFormLost.patchValue({
    reward: ''
  });
}
rewardControl.updateValueAndValidity();
}

How i can enable the 'reward' input box? Default state is disabled, when the user marks check box as true, i don't know how to enable it.

1 Answer 1

1

You can use one of these

this.renderer.setElementProperty(this.rewardAmountFocus.nativeElement, 'enabled', true);
this.renderer.setElementAttribute(this.rewardAmountFocus.nativeElement, 'enabled', 'true');

or set 'disabled', false

See also https://angular.io/docs/ts/latest/api/core/index/Renderer-class.html

Sign up to request clarification or add additional context in comments.

2 Comments

that worked using setElementProperty, thanks. The this.renderer.setElementAttribute(this.rewardAmountFocus.nativeElement, 'enabled', true); fires a argument of type boolean cannot be assigned to parameter of type string.
Sorry, setElementAttribute expects a string (should be 'true')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.