创建表单不起作用sapui5

时间:2017-03-14 12:18:06

标签: javascript sapui5 sap-fiori

我有一个使用OData服务的主 - 详细信息应用程序。

我还在片段中创建了一个名为" DetailCreateMode.fragment.xml"应该创建通知。不幸的是,它并没有创造它们。

这是我的片段:

 <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>

这是保存和创建的按钮:

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

最后但并非最不重要的是,这里是详细控制器中的功能:

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();  
    },

如果我猜一下,我说mNEwEntry.Equnr,......的值是未定义的

2 个答案:

答案 0 :(得分: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");

到此:

 mNewEntry.Equnr = this.byId("Equnr_id");
 mNewEntry.Qmtxt = this.byId("Qmtxt_id");
 mNewEntry.Qmdat = this.byId("Date Avis");

EDITED 17:10 140317:

示例:

https://sapui5.hana.ondemand.com/explored.html#/sample/sap.ui.layout.sample.SimpleForm480_Trial/preview

答案 1 :(得分:0)

您需要获取输入的值,如下所示:

mNewEntry.Equnr = sap.ui.getCore().byId("Equnr_id").getValue();
mNewEntry.Qmtxt = sap.ui.getCore().byId("Qmtxt_id").getValue();
mNewEntry.Qmdat = sap.ui.getCore().byId("Date Avis").getValue();
相关问题