Skip to Content
0

Custom Type validation not being called - UI5

Dec 06, 2017 at 09:54 PM

66

avatar image
Former Member

Hi,

I want to enable validations on a form inside a dialog fragment. Tried to follow the example like here: https://sapui5.hana.ondemand.com/#/sample/sap.m.sample.InputChecked/preview

but it simply doesn't call any of the 3 methods.

How do I bind the Message Manager to the fragment so any input inside it works?

[EDIT]

I tried using the default types validation, and yet not is showing up.
Detail.Controller onInit method has this:

var oMessageManager = sap.ui.getCore().getMessageManager();
oMessageManager.registerObject(this.getView(), true);

On a button press I have this:

var oView = this.getView();
oDialog = sap.ui.xmlfragment("com.tigre.sales.view.AddContactDialog", this);
oView.addDependent(oDialog);
var oContext = this._oODataModel.createEntry("ContactSet", { success: this._createContactHandler.bind(this), error: this._createContactHandler.bind(this) }); oDialog.setBindingContext(oContext); oDialog.open();

My fragment (AddContactDialog.fragment.xml):

<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:semantic="sap.m.semantic" xmlns="sap.m" xmlns:f="sap.ui.layout.form" xmlns:html="http://www.w3.org/1999/xhtml">
  <Dialog id="AddContactDialog" title="{i18n>AddContactDialogTitle}">
    <content>
      <f:SimpleForm columnsL="1" columnsM="1" editable="true" emptySpanL="4" emptySpanM="4" id="newContactSimpleForm" labelSpanL="3" labelSpanM="3" layout="ResponsiveGridLayout" maxContainerCols="2" minWidth="1024" title="{i18n>AddContactDialogTitle}">
        <f:content>
          <Label text="{i18n>ContactName}" required="true"/>
          <Input name="Person" type="Text" id="Person_id" valueLiveUpdate="true" value="{ path: 'Person', type: 'com.tigre.core.types.alphabet'}"/>
          <Label text="{i18n>Role}" required="true"/>
          <Input name="Role" id="Role_id" valueLiveUpdate="true" value="{ path: 'Role', type: 'sap.ui.model.type.String', constraints:{ maxLength:50 } }"/>
          <Label text="{i18n>Email}" required="true"/>
          <Input type="Email" placeholder="{i18n>emailPlaceholder}" name="Email" id="Email_id" valueLiveUpdate="true" value="{ path: 'Email', type: 'sap.ui.model.type.String', constraints:{ maxLength:50 } }"/>
          <Label text="{i18n>CellPhone}" required="true"/>
          <Input name="CellPhone" id="CellPhone_id" valueLiveUpdate="true" value="{ path: 'CellPhone', type: 'sap.ui.model.type.Decimal' , constraints:{ scale:0 } }"/>
        </f:content>
      </f:SimpleForm>
      <Toolbar>
        <ToolbarSpacer/>
        <Button type="Reject" text="Cancel" press="onCancelButtonPress"/>
        <Button type="Accept" text="Save" press="onSaveButtonPress" enabled="{viewModel>/enableCreate}"/>
      </Toolbar>
    </content>
  </Dialog>
</core:FragmentDefinition><br>

What am I doing wrong? Can't I make a form with validation inside a dialog?

10 |10000 characters needed characters left characters exceeded
Former Member

Just so you know, doing this in a normal view works just fine.

I suspect the problem is that the fragment is only created on the button press therefore the message manager doesn't know of its inputs yet. I've tried changing the message manager to after the init but still same result. Maybe the register object is not enought?

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Dec 12, 2017 at 05:46 PM
0

Never tried with the fragment, but the problem with the validation was that it was missing the constraint nullable: false as so:

<Input name="Email" id="Email_id" valueLiveUpdate="true" liveChange="_validateSaveEnablement" value="{ path: 'Email', type: 'sap.ui.model.odata.type.String', constraints: {nullable: false} }"/>

Share
10 |10000 characters needed characters left characters exceeded
Irfan Gokak Dec 07, 2017 at 02:08 PM
0

Hi,

Please share code how your creating fragment and opening it in controller. Also check below sample code if anything is missing.

// Common select dialog for all
openLstDlg : function(oEvent) {
	if (!this._listDlg) {
		this._listDlg = sap.ui.xmlfragment("com.ajva.oplZTR_QUATATN.fragments.List", this);
		this.getView().addDependent(this._listDlg);
	}
	this._listDlg.open();
},

Make sure you added this line. this.getView().addDependent(this._listDlg);

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Take a look above or bellow, I've added samples.

var oView = this.getView();
oDialog = sap.ui.xmlfragment("com.tigre.sales.view.AddContactDialog", this);
oView.addDependent(oDialog);
var oContext = this._oODataModel.createEntry("ContactSet", {
    success: this._createContactHandler.bind(this),
    error: this._createContactHandler.bind(this)
});
oDialog.setBindingContext(oContext);
oDialog.open();
0