Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 803f3b3

Browse files
authored
Merge pull request #8 from gradedcatfood/master
Update InertiaForm to handle latest version inertia 0.4 and inertia-vue 0.3
2 parents f3ad707 + 33f0aa2 commit 803f3b3

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"babel-preset-es2015": "^6.9.0"
3434
},
3535
"dependencies": {
36-
"@inertiajs/inertia": "^0.1.7",
36+
"@inertiajs/inertia": "^0.4.0",
3737
"prettier": "^1.10.2"
3838
}
3939
}

src/InertiaForm.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,25 @@ class InertiaForm {
138138
this.processing = true;
139139
this.successful = false;
140140

141-
const then = () => {
141+
const onSuccess = page => {
142142
this.processing = false;
143143

144144
if (! this.hasErrors()) {
145145
this.onSuccess();
146146
} else {
147147
this.onFail();
148148
}
149+
150+
if (options.onSuccess) {
151+
options.onSuccess(page)
152+
}
149153
}
150154

151155
if (requestType === 'delete') {
152-
return this.__inertia[requestType](url, options)
153-
.then(then)
156+
return this.__inertia[requestType](url, { ... options, onSuccess })
154157
}
155158

156-
return this.__inertia[requestType](url, this.hasFiles() ? objectToFormData(this.data()) : this.data(), options)
157-
.then(then)
159+
return this.__inertia[requestType](url, this.hasFiles() ? objectToFormData(this.data()) : this.data(), { ... options, onSuccess })
158160
}
159161

160162
hasFiles() {
@@ -266,15 +268,15 @@ export default {
266268
.withData(data)
267269
.withOptions(options)
268270
.withInertia(app.config.globalProperties.$inertia)
269-
.withPage(() => app.config.globalProperties.$page),
271+
.withPage(() => app.config.globalProperties.$page.hasOwnProperty('props') ? app.config.globalProperties.$page.props : app.config.globalProperties.$page),
270272
});
271273
} else {
272274
app.prototype.$inertia.form = (data = {}, options = {}) => {
273275
return InertiaForm.create()
274276
.withData(data)
275277
.withOptions(options)
276278
.withInertia(app.prototype.$inertia)
277-
.withPage(() => app.prototype.$page);
279+
.withPage(() => app.prototype.$page.hasOwnProperty('props') ? app.prototype.$page.props : app.prototype.$page);
278280
};
279281
}
280282
},

0 commit comments

Comments
 (0)