How to set a comments widget to readonly dynamically

Hello,

I’ve been trying to set a comments widget to readonly using the following code:

$$(‘commentsId’).config.readonly = true;
$$(‘commentsId’).refresh();

I’ve also tried:

$$(‘commentsId’).define(“readonly”,true);
$$(‘commentsId’).refresh();

But the comments widget is not disabling.

Thanks,
Pieter

Hi!
Unfortunately, thecomments don’t have refresh method .
As a solution you can use the queryView method to return texthighlight view and define readonly:true:

let view = $$("comments").queryView("texthighlight");
view.define({readonly:true});
view.refresh();

https://snippet.webix.com/yw60ya0u
Also you can use disable method:
https://snippet.webix.com/dbau5kbu

When I try the suggested queryView method, the view value is null and get a subsequent error ‘cannot read property ‘define’ of null’.

The disable method disables the whole widget and does not let you scroll thru the comments.

Hi @Pieter

Depending on the Webix version and settings, the Comments widget can include either Textarea or TextHighlight (which was presented in the recent version) as a text field.
To ensure the proper view is called, you can use the following declaration:

comments.queryView(comments.config.highlight ? "texthighlight" : "textarea")

But, as far as I can see, the textarea is correctly disabled while the rest of the content is fully available: https://snippet.webix.com/faw78ka4

Could you please provide a demo which can illustrate the issue?

I was applying the ‘disable’ to the comments widget directly instead of the textarea view.

Using '(comments.config.highlight ? “texthighlight” : “textarea”) works. Thank you Listopad.
Is there a way to hide the bottom edit section dynamically? I can set the retrieved ‘textarea’ view to hidden but that leaves an empty box. Can that be retrieved with a queryView statement as well? I’d like to have the comments widget in ‘read only’ mode show without the edit field box at the bottom. Is that possible?

Thanks for all the help,
Pieter

I think I have it solved. If I want the comments in readonly mode dynamically,
I get the ‘form’ of the comments widget and hide it.

let view = $$(“comments”).queryView(“form”);
view.hide();

and set the currentUser to an invalid user like 9999 so that there are no edit menus.