Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

OData: submitChanges for creates #627

Closed
themasch opened this issue Oct 6, 2015 · 2 comments
Closed

OData: submitChanges for creates #627

themasch opened this issue Oct 6, 2015 · 2 comments

Comments

@themasch
Copy link
Contributor

themasch commented Oct 6, 2015

Again I don't have a minimal example for this problem but some references to the code. Sorry for that 馃槥.
We're having an issue with submitChanges() to submit an entity created with createEntry().
When the first request is successful, everything works fine. The Context is updated, mChangedEntities is updated, hasPendingChanges returns false afterwards.

The problems start to happen when the first request fails. The user may have entered an invalid value, the backend responds with a HTTP 400 and some error messages. The user fixes his error, clicks "save" again. A new submitChanges() is triggerd. It creates a new request that does NOT contain a reference to the context created by createEntry() (because that gets assigned by createEntry). That way, the - now successful - response does not update the context nor mChangedEntities and by this, hasPendingChanges() returns true although the POST-Request went well.

This happens with useBatch=true and useBatch=false, no difference.

Has someone already solved that problem? Are we doing something wrong?
Here is roughly what we are doing:

onSave: function() {
    if(oModel.hasPendingChanges()) {
        oModel.submitChanges()
            .then(function() {
                if(this.oNewCtx) {
                    this.navTo("details", { id: this.oNewCtx.getPath() })
                }
            }).catch(console.error.bind(console));
    } 
}, 
onNewDetail: function() {
    this.oNewCtx = oModel.createEntry("/Collection", ..);
    oView.setBindingContext(this.oNewCtx);
},
onChangeDetail: function() {
    if(oModel.hasPendingChanges()) {
        MessageBox.show("You have unsaved changes!");
        return;
    }
    // change binding here...
},
onBack: function() {
    oModel.resetChanges();
    this.navTo("somewhere far far away");
}

So we currently depend on hasPendingChanges() to check if the changed/created entity has unsaved changes. This works for updates & "perfect" creates but failes only for the case described above.

@matz3
Copy link
Member

matz3 commented Oct 12, 2015

f75e47d seems to be related to this issue.
@loginger can you have a look if your change should solve this?

@DMihaylova
Copy link
Contributor

DMihaylova commented Dec 2, 2016

Hi @themasch ,

Do you still experience this issue or it was fixed with the change that @matz3 listed above?
Feel free to reopen if it still persist.

Thanks and Kind Regards,
Diana, SAPUI5 Dispatcher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants