any help with this ?
Jun 6, 2015
9
Level 15
vue send an empty value and response is the field required
hello every one
today i start to work with vuejs
and my form is just having field (name) and submit button
so when i try to debug the post request it send whatever i put in the input field and after submitting the form its only send empty string and the response is the field name is required
this is my code
the JS app file
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');
new Vue({
el: '#create-form',
data: {
newName: '',
},
methods: {
onSubmitForm: function(e) {
e.preventDefault();
var name = this.newName;
this.newName = '';
this.$http.post('manufacturer', name);
}
}
});
the HTML view
<div id="create-form" class="module-body">
<form method="POST" v-on="submit: onSubmitForm">
<div class="form-group">
<label for="name">
Manufacturer Name:
</label>
<input type="text" name="name" id="name" class="form-control" v-model="newName">
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">
Add Manufacturer
</button>
</div>
</form>
<pre>
@{{ $data | json }}
</pre>
</div>
and this is my Store Method it work fine with normal form
public function store(ManufacturerRequest $request)
{
Manufacturer::create($request->all());
return redirect()->action('ManufacturersController@index');
}
Level 15
@bobbybouwmann i found the solution
just make the data as array >_<
data: {
newInput: { name: ''},
},
onSubmitForm: function(e) {
e.preventDefault();
var input = this.newInput;
this.newInput = { name: ''};
this.$http.post('manufacturer', input);
}
<input type="text" name="name" id="name" class="form-control" v-model="newInput.name">
is there some explanation why its accept it as array ?? and not as normal var ?
or i miss understand something >_<
Please or to participate in this conversation.