angular icon indicating copy to clipboard operation
angular copied to clipboard

refresh form with readOnly has no affect

Open dolphinsd opened this issue 7 years ago • 15 comments

In a simple use case, after a form is submitted we set readOnly to true and emit this.refreshForm.emit({ submission: this.submission, readOnly: this.viewOnly }); None of the above have any affect on existing form.

Also, if you set [readOnly] to true in ngOnInit it has no affect as well.

We thought it should respect refresh options?

The code onRefresh(refresh: FormioRefreshValue) does use update viewOnly and readOnly options.

dolphinsd avatar Aug 03 '19 07:08 dolphinsd

It is possible that this was broken in a recent release. What version of the core renderer are you using?

travist avatar Aug 05 '19 15:08 travist

WE are 3.24.0

dolphinsd avatar Aug 08 '19 16:08 dolphinsd

readOnly is an option within the renderer. You may need to set that property directly on the FormioComponent instance like this.

@Component({
  ...
})
export class MyComponent implements AfterViewInit {
  @ViewChild(FormioComponent, {static: true}) formioComponent: FormioComponent;

  ngAfterViewInit() {
    this.formioComponent.formioReady.then(() => {
      this.formioComponent.formio.disabled = true;
    });
  }
}

travist avatar Aug 12 '19 14:08 travist

I too am having an issue with refresh and readOnly. I currently am developing this as an Ionic 4 Angular 7 mobile app. The emitting of the refresh is not changing the status of my form between readOnly or not while on the page. I have to leave the page and return for the form to change its status.

alland67 avatar Sep 01 '19 00:09 alland67

@alland67 have you tried my suggestion ^

travist avatar Sep 03 '19 14:09 travist

Travist, Yes I did try your suggestion and still not worked. For myself I made my use case work by displaying the formio render directive in two separate divs on my page toggling the div with an *ngIf based on whether to show it as readonly or not.

Allan

alland67 avatar Sep 03 '19 14:09 alland67

@travist We are experiencing a similar issue. The code below does not set the readOnly property of the formioComponent to this.interaction.isReadOnly. It always takes the default value. If we trigger a change event, ngOnChanges is executed again and the value is set and form correctly rendered.

ngOnChanges(changes: SimpleChanges) {
  if (changes.interaction) {
    this.formioComponent.readOnly = this.interaction.isReadOnly;
  }
}

elibus avatar Mar 07 '20 16:03 elibus

I believe it should be changes.instance instead of changes.interaction.

Also, I don't believe we are watching this "readOnly" flag and setting the renderer there. Try this instead.

if (changes.instance) {
  this.formioComponent.formio.disabled = this.instance.disabled;
}

travist avatar Mar 09 '20 15:03 travist

Hi @travist , someone in the team managed to solve it. Thanks anyway.

elibus avatar Mar 09 '20 20:03 elibus

@travist to complement my previous comment, we worked around it but it's not currently working as expected. Looks like changing the readOnly property to public and following your advice works. Someone from the team will post a comment/pr on this.

elibus avatar Mar 17 '20 09:03 elibus

Setting this.formioComponent.readOnly works and could be bound via template as well. However, we need to make sure that it's set before the component is rendered. For that you (@travist) suggested waiting until the component is ready using this.formioComponent.formioReady, which is a private property though.

I suggest to make formioReady public. I could make this change and create a pull request.

marwgit avatar Mar 17 '20 10:03 marwgit

@marwgit if you submit that pull request, I will accept it. Thanks.

travist avatar Mar 17 '20 15:03 travist

Thank you. It's already there (#495).

marwgit avatar Mar 17 '20 15:03 marwgit

somehow this way of dynamically switching the form readonly is not reflecting for me.

dev-thinks avatar Aug 22 '20 02:08 dev-thinks

We're currently addressing a backlog of GitHub issues, and as part of this effort, some inactive issues may be marked as closed. This isn't a dismissal, but a step toward more efficient tracking.

If you feel the issue is still relevant, please re-open and we'll ensure it gets the attention it deserves. Your understanding is appreciated as we work to enhance our open-source responsiveness.

Sidiro23 avatar Feb 07 '24 14:02 Sidiro23