ngx-inline-editor icon indicating copy to clipboard operation
ngx-inline-editor copied to clipboard

Dynamically enabling and disabling inline-editor does not work

Open mumairofficial opened this issue 8 years ago • 11 comments

I am working on pilot project and I figured out if toggle editable status dynamically then it does not work. angular version is 4.4.4 and cli 1.4.4

here is example piece

<inline-editor type="text" [(ngModel)]="eventDetails.title" disabled="!isEditable" (onSave)="onUpdateEventDetail({title: $event})" size="8"></inline-editor>

IsEditable Enabled: {{isEditable}} <- this toggled but inline-editable didn't show input box

<button class="btn btn-default" (click)="onToggleEditableFields()">Edit Values</button>

Ts:

export class MyComponent {
  public isEditable = false;

  public onToggleEditableFields(): void {
    this.isEditable = !this.isEditable;
  }
 // .... more code
}

I also have tried [disabled] no progress. Please guide me if I am doing it wrong.

mumairofficial avatar Sep 29 '17 23:09 mumairofficial

Hi @mumairofficial, it's working for me. I have copied your example, but I'm using [disabled] instead of disabled, it's required.

tonivj5 avatar Oct 01 '17 17:10 tonivj5

+1 This also doesn't work for me :(

flaska avatar Oct 19 '17 15:10 flaska

<inline-editor type="textarea" [(ngModel)]="descriptor.concept[0].scopeNote" [disabled]="!editMode" (onSave)="elementModified.emit()" id="scope_note" cols="100" rows="6"></inline-editor>

flaska avatar Oct 19 '17 15:10 flaska

Please @fleska or @mumairofficial, can you provide us a demo or reproducible repo? Because it is working for me. Thanks :+1:

tonivj5 avatar Oct 30 '17 10:10 tonivj5

@xxxtonixxx I was very busy in project hopefully following will help you to understand the problem.

Note: I am using [disabled] in following example, and gif shows disabled without [] brackets

You will notice after toggling; cursor is still disabled (can't edit the value) inline-editor-problem

Reproduce steps:

  • Brand new angular-cli based project
  • installed inline-edit, bootstrap, font-awesome and
app.component.html
<div class="container">
  <div class="form" style="text-align: center; margin-top: 100px">
    <strong>Simple</strong>
    <inline-editor type="text" [(ngModel)]="default" (onSave)="saveEditable($event)" name="default" size="8"></inline-editor>
    <br>
    
    <strong>disabled="false"</strong>
    <inline-editor type="text" [(ngModel)]="withFlgFalse" (onSave)="saveEditable($event)" name="withFlgFalse" [disabled]="false"
      size="8"></inline-editor>
    <br>
    
    <strong>disabled="true"</strong>
    <inline-editor type="text" [(ngModel)]="withFlgTrue" (onSave)="saveEditable($event)" name="withFlgTrue" [disabled]="true" size="8"></inline-editor>
    <br>
    
    <strong>disabled="isEditable"</strong>
    <inline-editor type="text" [(ngModel)]="withIsDisabledFlg" (onSave)="saveEditable($event)" name="withIsDisabledFlg" [disabled]="isEditable"
      size="8"></inline-editor>
    <hr>
    <a (click)="toggleEdit($event)">Toggle isEditable</a> | IsEditable: <strong>{{isEditable}}</strong>
  </div>
</div>
app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'My component!';
  isEditable = true;

  default = 'Default example';
  withIsDisabledFlg = 'With isDisabled flg';
  withFlgTrue = 'disabled flg true';
  withFlgFalse = 'disabled flg false';

  saveEditable(value) {
    console.log('http.service: ' + value);
  }

  toggleEdit(e) {
    e.preventDefault();
    this.isEditable = !this.isEditable;
  }
}

mumairofficial avatar Oct 30 '17 13:10 mumairofficial

Very good demo! It was exactly the same problem for me. :+1:

flaska avatar Oct 30 '17 14:10 flaska

Thank you very much for you effort @mumairofficial, I think it is enough to test it :+1:

tonivj5 avatar Nov 02 '17 22:11 tonivj5

+1 not working for me either.... :(

mandeeps1 avatar Nov 09 '17 11:11 mandeeps1

@mumairofficial How would it benefit you from opening a input field that is disabled? I want it to be enabled when i open it by button press.

Rassamdul avatar May 09 '18 09:05 Rassamdul

@Rassamdul thank you for comment... Actually I forgot the scenario; basically I was trying to enable/disable pragmatically based upon some criteria

mumairofficial avatar May 09 '18 10:05 mumairofficial

This also doesn't work for me , anyone got the solution??

divya130 avatar Jul 11 '18 09:07 divya130