13

This is what I have right now. Trying to call the checkToEnable function.

<input type="text" ([ngModel])="city.arr.date" [id]="city.id+'_arr_date'" [name]="city.id+'_arr_date'" [attr.disabled]="selectedTripType=='OT' ? true : null" class="input-icon-date input-default-last  form-control" (click)="checkToEnable()" placeholder="Return Date"/>
8
  • Whats the issue with this? Commented Oct 24, 2017 at 5:31
  • @VivekDoshi Doesn't go inside the function when disabled Commented Oct 24, 2017 at 5:33
  • May be click is not triggered for disabled. Try (mousedown)="checkToEnable()" Commented Oct 24, 2017 at 5:35
  • @SaurabhTiwari (mousedown) doesn't help. Commented Oct 24, 2017 at 5:38
  • Then may be you need not use disabled. Rather try to imitate a disabled css. Commented Oct 24, 2017 at 5:43

2 Answers 2

20

Disabled elements don't fire mouse events. Most browsers will propagate an event originating from the disabled element up the DOM tree, so event handlers could be placed on container elements.


But you can achieve it by this way :

Component Side:

disableTextbox =  false;

toggleDisable() {
    this.disableTextbox = !this.disableTextbox;
}

Template side :

<div (click)='toggleDisable()'>
  <input [disabled]='disableTextbox' >
</div>

WORKING DEMO

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

5 Comments

@Lasitha, glad to know that :) .
@VivekDoshi can you please help me to solve this stackoverflow.com/questions/52272192/…
seems that it does'nt works with buttons: toggleDisable() click fires when user clicks outside the button.
Brilliant, didn't expect such a simple solution !
This solution does not seem to work on Firefox. I'm running version 89.0.
1

You can use css of an element inside a disabled input / form-field and re-activate the click events for that by adding css pointer-events: all;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.