Add items in selector via code that can't be removed by editor


#1

Enonic version: 7.0.2
OS: Ubuntu 19

Hello again, is it possible? I need to add some items in my custom selector via code and I need the editor to not be able to remove those from there but still be able to add and remove others, to simple disable the entire selector would be nice too.


#2

Are you talking about Custom selector or the Html editor?
I’m not able to interpret your question, as to what is your use-case?


#3

By editor I meant the user that edits content in the Content Studio, so what I want to do is, on a Custom Selector:

  • Add Items via code;
  • Those Items can’t be deleted by the User inside Content Studio;
  • The User can add Items to this Custom Selector;
  • Items added by the User can be deleted in Content Studio;

Either that or simply have a Custom Selector that can’t be edited in Content Studio.


#4

Hi,

This is not possible today, but you can always hard code your own list of items using their keys/IDs in the controller itself.


#5

I see, what I plan to do then is to create a Listener and re-add any deleted Item that I would first want to disable in the Content Selector (not using a Custom Selector anymore) when a Content is saved. Now I have another question, in a selected Item:
Screenshot%20from%202019-09-26%2011-39-52
Is it possible to alter anything there? Like remove icons or add text.


#6

So, what you actually want is to store and index a set of properties automatically when a content is created or updated?

Will the properties always be the same, or vary based on context?


#7

I guess yes, and any way would be fine. So what I initially wanted to do is to make my Content Selector look more like this image:
Screenshot%20from%202019-09-26%2013-47-54-2
Either insert items like Test3 or have something like the class non-editable applied to both functions like in Test and to be able to disable the selection of new Items.


#8

I didn’t really knew how a Custom Selector worked, after learning a little more what I did was to add a tag in the value saved as ID to differentiate what was inserted via code from what was inserted by the user, then on a listener I check if any item added via code was removed by the user and if so I add it back, not pretty tho. Anyway, thanks a lot.