cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP CAP: Is there any way to modify UI annotations via nodejs events in CAP?

0 Kudos
336

I want to modify/add the readonly property of some fields based on another table to make them editable/non-editable.

I tried with approaches like:

req.target.elements.description["@readonly"] = true
req.target.elements.description._isReadOnly = true...
 
But none of them working. Also tried to put them in the .before, .on and .after and no luck.
Is it possible to do this like im doing? Or I should change the approach?

Accepted Solutions (1)

Accepted Solutions (1)

MattBrightman
Explorer

I think you should change your approach but the outcome you want is achievable. 

Take a look at this documentation: https://sapui5.hana.ondemand.com/sdk/#/topic/f49a0f7eaafe444daf4cd62d48120ad0.html

You will be particularly interested in the @ui.Hidden and  @Common.FieldControl annotations.  

This fiori elements annotation shows how you could dynamically control the visibility of a field: 

entity ProductsType : {
    UI.FieldGroup #AdministrativeData : {
    Data : [
        {
            $Type : 'UI.DataField',
            Label : 'Modified at',
            Value : ModifiedAt,
            ![@UI.Hidden] : HasDraftEntity,
        },
    ],
},
}

You could easily replace 'HasDraftEntity' with a virtual field you calculate

Also checkout the SFLIGHT scenario as that makes fields readonly based off the status:

https://github.com/SAP-samples/cap-sflight/blob/main/app/travel_processor/field-control.cds

0 Kudos

Hi Matt,

Thanks for replying. Finally, I chose that approach. I declared virtual fields for each field and made the logic for them in a node.js event. I wonder if there is any better workaround for this, because its not very elegant as Im declaring a virtual field per normal field (I have a lot)...

Answers (0)