cancel
Showing results for 
Search instead for 
Did you mean: 

Mark field as mandatory in Fiori app through CDS annotations

kellydurantauli
Discoverer

I've created a Fiori app in Web IDE using the list report template based on CDS views.

I want to make a few of the fields mandatory when editing a record. I've added the annotation:

@ObjectModel.mandatory: true

for each of the fields I want to be mandatory on my business object CDS view.

The result of this annotation on the app is that I see a red asterisk next to the field. However, nothing really happens if I edit the record and hit Save with the mandatory field being blank - I am able to successfully save the values even if the mandatory fields are empty.

Am I missing something? I would expect to get an error for the mandatory fields.

Accepted Solutions (0)

Answers (8)

Answers (8)

ChrisL
Advisor
Advisor

Hi,

I faced exactly the same problem.

After searching through different blogs and documentations, I finally found the following solution, which worked for me using BOPF and Fiori Elements:

1. Ensure that your annotation
@ObjectModel.mandatory: true
is used on the transactional CDS layer, i.e. the CDS that creates the BOPF object.

2. In the BOPF you have to add a validation, lets call it Mandatory_Check and put in the class /BOBF/CL_LIB_V_MANDATORY_ATTR and activate. You do not need to implement anything, the library takes care automatically.

As a result you will be notified in your Fiori app, when you try to save the entity without setting a values for the field you annotated.

Hope, this helps.

Best

Christian

developerone
Contributor

Sorry, I have misunderstood your requirement. I have tried this a few months back and I recollect the annotation in CDS only marks field with an asterisk. I had to explicitly code my validations in the controller.js.

kamal_kaur30
Discoverer
0 Kudos

Hi All,

Any pointers. Facing the same issue.

Regards,

Kamalpreet Kaur

0 Kudos

Hi Kelly,

Were you able to solve this issue?

I am also facing the same.

Regards,

Rahul Kumar Jain.

0 Kudos

Hi Pierre Dominique,

I am facing the same issue did you get any solution to that.

0 Kudos

Hi Poornima,

I am also facing the same issue to validate mandatory fields in Object Page.

Could you please let me know if you were able to solve this issue?

Thanks & Regards,

Rahul Kumar Jain

former_member321811
Participant
0 Kudos

Hi,

I have the same issue. Using nullable="false" for my OData property, everything works as expected (i.e value state is set to Error and the request is not sent when the field is empty) but this solution is not dynamic. Using the field-control (i.e mandatory) annotation, the field is marked as mandatory in the UI but the form data is not checked and the request is submitted even if the required field is empty.

How can we check the form data before sending the request using the List Report + Object Page template?

Cheers,

Pierre

0 Kudos

Hi Pierre,

I am also facing the same issue to validate mandatory fields in Object Page.

Could you please let me know if you were able to solve this issue?

Thanks & Regards,

Rahul Kumar Jain

Bernard
Participant
0 Kudos

Hi,

You would have to check through the controls - I do this by passing through a list of controls to the below function and then iterate through, in the case below, the input controls (convention based checking based on my control names - i.e. they start with 'input'.

If they have no value I set their state to error and return false defining whether the action should proceed.

There are properties you can set on the control itself as well to validate other aspects.

Let me know if you need more detail.

        CheckForNoInput: function(controls){
            jQuery.each(controls, function (i, control) {
                if (control.getId().startsWith("input")){
                    if (!control.getValue()) {
                        control.setValueState(sap.ui.core.ValueState.Error);
                    }
                }
             });
        }
developerone
Contributor
0 Kudos

Hello Kelly,

Please go through this thread.

Thank You,

Sai

kellydurantauli
Discoverer
0 Kudos

Thank you for your reply.

Unfortunately I've already looked at the thread mentioned and it does not resolve my issue. The thread is about a mandatory search field, and what I am looking for is to make editable fields in the object page as mandatory