I am trying to use a sap.m.Dialog popup where the contents comes from a view, because fragments does not fully allow using custom controller.
The basic things are working as expected, but the controller fire onInit, but does not fire onAfterRendering (no output in lifecacle event!?!).
I tried to attach ValdiationError/Success handler, but the dialog input fields does not fire Validation errors!
All the code works well for Pages inside apps, but i think there is something wrong with Dialogs using Views.
The core models are also not available inside the view.
For my app/pages this works out-of-the-box.
After workaround
oView.setModel(oCore.getModel("i18n"), "i18n");
i am able to access i18n model inside view.
So i think there is something going wrong in the core.
I am not able to reproduce this easily for you on jsbin because using views, but i added the main used logic. I also tried to stripdown the view to dialog/input only but got the same result (thaught the issues are inside simpleform or gridlayout).
The Dialog is shown using
if (!this._selfregistrationView) {
this._selfregistrationView = sap.ui.xmlview(
"selfregistration-view", "view.login.SelfregistrationDialog"
);
}
this._selfregistrationView.byId("selfregistrationDialog").open();
The controller looks like this:
var oCtrl = sap.ui.controller("view.login.Selfregistration", {
onInit: function() {
var oView = this.getView(),
oCore = sap.ui.getCore();
console.log("onInit");
oCore.attachValidationSuccess(this.onValidationSuccess, this);
oCore.attachValidationError(this.onValidationError, this);
var oViewModel = new sap.ui.model.json.JSONModel();
oViewModel.setData({
username: "Holger",
});
oView.setModel(oViewModel);
oView.setModel(oCore.getModel("i18n"), "i18n");
onAfterRendering: function() {
console.log("onAfterRendering");
},
onValidationSuccess : function(oEvent) {
console.log("onValidationSuccess");
if (oElement.setValueState) oElement.setValueState(sap.ui.core.ValueState.None);
},
onValidationError : function(oEvent) {
console.log("onValidationError");
if (oElement.setValueState) oElement.setValueState(sap.ui.core.ValueState.Error);
}
});
The XML view is something like
<core:View controllerName="view.login.Selfregistration"
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:l="sap.ui.layout"
xmlns:f="sap.ui.layout.form" >
<Dialog title="{i18n>UME_SELFREGISTRATION_TITLE}" icon="sap-icon://activity-individual"
id="selfregistrationDialog"
contentWidth="96%" contentHeight="96%" stretchOnPhone="true">
<content>
<l:Grid defaultSpan="L12 M12 S12" xwidth="auto">
<l:content>
<f:SimpleForm id="SimpleForm" class="editableForm"
xminWidth="1024" maxContainerCols="2" editable="true" layout="ResponsiveGridLayout"
labelSpanL="3" labelSpanM="3" emptySpanL="0" emptySpanM="0" columnsL="2" columnsM="2">
<f:content>
<core:Title text="{i18n>GENERAL}" />
<Label text="{i18n>UME_USER_NAME}" required="true" />
<Input id="username" name="username" placeholder="{i18n>UME_USER_USERNAME}"
valueStateText="Min 2 chars"
value="{
path: 'username',
type: 'sap.ui.model.type.String',
constraints: {
minLength: 2,
search: '^(?=[\\w\\d]{5,}$)'
}
}" >
</f:content>
</f:SimpleForm>
</l:content>
</l:Grid>
</content>
<beginButton>
<Button text="{i18n>REGISTER}" type="Accept" icon="sap-icon://accept" press="onDialogSubmitButton" />
</beginButton>
<endButton>
<Button text="{i18n>CANCEL}" type="Reject" icon="sap-icon://sys-cancel" press="onDialogCancelButton" />
</endButton>
</Dialog>
</core:View>
Maybe i am doing something wrong or Dialog Popups are not supported, but everything is working as expected but the core event handling seems to fail (Input field validation) and also some lifecycyle hooks like onAfterRendering are not fired. Event the global model is not accessible from dialog view.
Any Idea?