Skip to Content
0

Create form i sapui5

Mar 14, 2017 at 03:05 PM

31

avatar image

Hello everyone, i started recently learning sapui5 to create applications FIORI.

I have a master-detail application that consumes an OData service.

I also have a "create form" in fragment named "DetailCreateMode.fragment.xml" that's

supposed to create notifications. Unfortunatly, it does not create them.

Here's my fragment :

<core:FragmentDefinition height="100%" width="100%" xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout"     xmlns:f="sap.ui.layout.form">
<Panel>
<content>
<f:SimpleForm id="iconTabFilter1form" minWidth="1024" editable="false" layout="ResponsiveGridLayout" labelSpanL="3" labelSpanM="3"
            emptySpanL="4" emptySpanM="4" columnsL="1">
            <f:content>
                <Label text="Equipement" required="false"/>
                <Input name="Equnr" id="Equnr_id" valueLiveUpdate="true" liveChange="_validateSaveEnablement"
                enabled="false" visible="true"
                value="{ path: 'Eqktx', type: 'sap.ui.model.odata.type.String' , constraints:{ maxLength:18, nullable:false } }"/>

                <Label text="Désignation" required="true"/>
                <Input name="Qmtxt" id="Qmtxt_id"     valueLiveUpdate="true" liveChange="_validateSaveEnablement"
                enabled="true" visible="true"
                value="{ path: 'Qmtxt', type: 'sap.ui.model.odata.type.String' , constraints:{ maxLength:40, nullable:false } }"/>

                <Label text="Date Avis" required="true"/>
                <DatePicker id="Qmdat" displayFormat="short" change="_validateSaveEnablement"
                 value="{ path: 'Qmdat', type: 'sap.ui.model.type.Date', formatOptions: { style : 'long' }  }"/>    

            </f:content>
        </f:SimpleForm>
    </content>
</Panel>

Here's the button that saves :

<Button id="saveButton" press="saveChanges" icon="sap-icon://save"></Button>

And last but not least, here's my controller's function :

saveChanges: function() {
    var oModel = this.getView().getModel();
    var mNewEntry = {};

    mNewEntry.Equnr = sap.ui.getCore().byId("Equnr_id");
    mNewEntry.Qmtxt = sap.ui.getCore().byId("Qmtxt_id");
    mNewEntry.Qmdat = sap.ui.getCore().byId("Date Avis");
    oModel.create("/avisSet", mNewEntry, null, function(oData){
        MessageBox.show(
            "Created succesfully",{
            icon : sap.m.MessageBox.Icon.SUCCESS,
            title : "Dear User",
            styleClass : "sapUiSizeCompact"
            }
            );
    }, function(err){
        MessageBox.show(
            "ERROR",{
            icon : sap.m.MessageBox.Icon.ERROR,
            title : "Dear User",
            styleClass : "sapUiSizeCompact"
            }
            );
    }
    );
      oModel.refresh();  
    },

If i take a guess, i'd say that the values mNewEntry.Equnr, ... are undefined

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jun Wu Mar 14, 2017 at 03:28 PM
0

mNewEntry.Equnr =sap.ui.getCore().byId("Equnr_id");

    mNewEntry.Qmtxt =sap.ui.getCore().byId("Qmtxt_id");
    mNewEntry.Qmdat =sap.ui.getCore().byId("Date Avis");

never do this.

use model binding.

Share
10 |10000 characters needed characters left characters exceeded