on 10-31-2018 10:27 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
Any pointers. Facing the same issue.
Regards,
Kamalpreet Kaur
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kelly,
Were you able to solve this issue?
I am also facing the same.
Regards,
Rahul Kumar Jain.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pierre Dominique,
I am facing the same issue did you get any solution to that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
}
});
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.