Skip to content

Commit 280e244

Browse files
committed
Fix problem when using FormData
Related to laravel/framework#13457
1 parent bb33b4e commit 280e244

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laravel-form-js",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A javascript representation of a form",
55
"main": "dist/Form.js",
66
"scripts": {

src/Form.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class Form {
5656
container.set(field, this[field]);
5757
}
5858

59+
if (this.method != 'post') {
60+
container.set('_method', this.method);
61+
}
62+
5963
return container.data;
6064
}
6165

@@ -94,7 +98,7 @@ class Form {
9498
}
9599

96100
return new Promise((resolve, reject) => {
97-
this.axios[this.method](url, this.data(dataType))
101+
this.axios.post(url, this.data(dataType))
98102
.then(response => {
99103
this.formSubmitSucceded(response);
100104
resolve(response);

tests/form.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,18 @@ test('can retrieve the errors for a specific field', () => {
4545

4646

4747
test('it retrieves the form data as a json', () => {
48-
let form = Form.makeFrom({name: 'test', email: 'test@mail.com'});
48+
let form = Form.makeFrom({name: 'test', email: 'test@mail.com'}, 'put');
4949

50-
expect(form.data('json')).toEqual({name: 'test', email: 'test@mail.com'});
50+
expect(form.data('json')).toEqual({name: 'test', email: 'test@mail.com', _method: 'put'});
5151
});
5252

5353
test('it retrieves the form data as a FormData', () => {
54-
let form = Form.makeFrom({name: 'test', email: 'test@mail.com'});
54+
let form = Form.makeFrom({name: 'test', email: 'test@mail.com'}, 'patch');
5555

56-
let data = new FormData();
57-
data.append('name', 'test');
58-
data.append('email', 'test@mail.com');
59-
60-
expect(form.data('form-data')).toEqual(data);
56+
let data = form.data('form-data');
57+
expect(data.get('name') == form.name).toBeTruthy();
58+
expect(data.get('email') == form.email).toBeTruthy();
59+
expect(data.get('_method') == form.method).toBeTruthy();
6160
});
6261

6362
test('can submit the form and use promises to receive the results', () => {

0 commit comments

Comments
 (0)