SAPUI5 Smart Table - Smart Field make field mandatory with annotation

Related searches

Is it possible to make a Property in SAPUI5 Smart Table mandatory so that a user can't leave a field empty while editing it?

I have found this document saying that it should be possible to set mandatory field control on Property in metadata.xml file with annotation like this:

<Property Name="NameLast" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Last name" sap:field-control="7" />

But with this setting I am getting following error in console:

2017-04-14 11:37:36.691429 MockServer: Resource not found for the segment '7' 
2017-04-14 11:37:36.707985 The following problem occurred: HTTP request failed404,Not Found,{"error":{"code":404,"message":{"lang":"en","value":"Resource not found for the segment '7'"}}} -  

EDIT:

Later I found out that sap:field-control should not contain number, but a path expression to another property which contains the number. However this also doesn't work:

<Property Name="NameLast" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Last name" sap:field-control="Name_fc" />
<Property Name="Name_fc" Type="Edm.Byte" />

Value of Name_fc property is '7'. I don't see any console error now, however I can still leave the input (NameLast) field empty without any validation and send it to OData service, which is not what I expect.

Here is a link to an example from sap where they use required fields. I have no idea though how they made it. https://sapui5.netweaver.ondemand.com/sdk/explored.html#/sample/sap.ui.comp.sample.smartfield/code/SmartField.view.xml

For OData v2 the sap:field-control annotation on the Property can be used to specify whether the field is mandatory.

 <Property Name="Customer" ... sap:field-control="mandatory"/>   
 <Property Name="CompanyCode" ... sap:field-control="mandatory"/>

https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.comp.smartfield.SmartField.html

SAPUI5 Smart Table - Smart Field make field , For OData v2 the sap:field-control annotation on the Property can be used to specify whether the field is mandatory. <Property� SAPUI5 Smart Table - Smart Field make field mandatory with annotation Posted on Apr 14, 2017 at 05:25 PM | 1.3k Views Follow

The mandatory property of the entity has to be nullable="false". That's it.

Have a look at the smart field example from your link:

            <Property Name="Name" Type="Edm.String" Nullable="false"
                MaxLength="30" sap:label="Name" sap:creatable="false"
                sap:quickinfo="Property annotation DataFieldWithUrl"
                sap:updatable="true" sap:sortable="false" />

Btw. thanks for sharing your smart table example!

Smart Field, The behavior can only be made more restrictive on client side, for example, if an OData property is mandatory, this cannot be overwritten on SmartField control� Smart Field The sap.ui.comp.smartfield.SmartField control offers a wrapper for other controls using OData metadata to determine which control has to be instantiated and makes it possible to add input-enabled fields to an application.

From my understanding there are 2 options:

1) Define a specific property as Mandatory --> Nullable="false"

2) Link a property to another property in the entity, the "field-control". This field control can contain numbers and "7" means mandatory.

The linking from option 2 can be done in the MPC_EXT class (redefine the define method). The actual value in the "field-control" property is set in the get_entity / get_en

However I am also having an issue with the smarttable. The mandatory fields do not light up red when empty.

sap.ui.comp.smartfield.SmartField, SmartField control offers a wrapper for other controls using OData metadata to The entity set to which the bindings are related is either specified in the The following table shows a selection of the annotations used by the SmartField control: property is mandatory, this cannot be overwritten on SmartField control level. Enables sorting for a table column. Filtering. sap:filterable. Enabled by default when 'null' Enables filtering for a table column. Ignoring backend fields. sap:visible 'false' Disables processing of an OData field of the SmartTable. Fields with value 'false' are not shown on table personalization panels. Summed values. sap:aggregation-role

Do it in brute force way in the Object Page extension controller.

var oField = this.getView().byId(<FieldId>)
oField.getDataProperty().property.nullable = "false" or "true". 
"false" and "true" must be a string.

To convert a boolean to string use <boolean>.toString();

Smart Field - Documentation - Demo Kit, If the SmartField control is rendered inside a smart container control, for example, the property annotated as Nullable="false" , the mandatory validation is performed on the client side The name of an entity set for which the control manages values. The event is fired after the smart field has calculated its metadata. Assume of a situation where as a user you would like to see 2 inter-related fields combined with each other under a single column instead of 2 different columns. Assume another situation where the data is getting displayed in a table but you want to change the look of data using a formatter.

For more information about annotations for this control, see the API Reference. In addition, the SmartField control implements field control and supports message handling. In combination with a SmartTable control The entity set to which the bindings are related is either specified in the Whether input is mandatory. Step 7: Create the Line Item Annotation which is the most important one for Smart table as it will help the UI5 framework to create table structure. Choose the line item column and then click on Create Annotation. Step 8: Click on ‘Append Row/Create’ Step 9: Choose the highlighted type for property. Step 10: One column is created as shown

Part1 – Currency example – how Smart field works. Part2 – Smart field with value help. Part3 – Smart Field with Smart Link. Part4 – this blog. The appearance of smart table rendered looks like below: The source code of this example could be found from this link. How table related annotation is parsed and table columns are rendered

For more info Check out my Blog www.beginners-sap.com Creating a FIORI application using List Report FIORI Elements - Introduction to OData Annotations and Annotation Modeler in WEBIDE. - m.

Comments
  • Could you please also post the full metadata.xml ?
  • metadata.xml is here - jsfiddle.net/sL2zrt8j
  • Unfortunately your solution leads to the same error: Resource not found for the segment 'mandatory' - The following problem occurred: HTTP request failed404,Not Found,{"error":{"code":404,"message":{"lang":"en","value":"Resource not found for the segment 'mandatory'"}}}