refresh form with readOnly has no affect
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.
It is possible that this was broken in a recent release. What version of the core renderer are you using?
WE are 3.24.0
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;
});
}
}
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 have you tried my suggestion ^
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
@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;
}
}
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;
}
Hi @travist , someone in the team managed to solve it. Thanks anyway.
@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.
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 if you submit that pull request, I will accept it. Thanks.
Thank you. It's already there (#495).
somehow this way of dynamically switching the form readonly is not reflecting for me.
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.