Make specific fields readonly in edit mode

I want to make some fields readonly in edit mode. What is the correct approach to do that? Currently I am setting editable false in onInit event and true in onInitEntity event, this way fields are these fields are editable in create mode only.

Hi

Please set in screen descriptor for the field editable - false (use Component Inspector or add attribute to xml tag editable="false")

.
And, as you did, add the onInitEntity event. Then inject the field into the screen controller, and set editable-true. For example:

    @Inject
    private TextField<String> nameField;

    @Subscribe
    public void onInitEntity(InitEntityEvent<NewEntity> event) {
        nameField.setEditable(true);
    }

After that, all calls to the edit screen, except for creating a new entity, make the attribute unavailable for editing.

Regards,
Vera

1 Like

Thanks Vera. This is the right approach :+1: