After reviewing the documentation, I attempted to implement the code provided. While I am able to successfully retrieve data for enquiryDesc
, I am consistently getting a value of 5 for the rating field. I even experimented with changing the radio group to a checkbox, but unfortunately, it did not yield the desired outcome.
This is how my html
form looks:
<form id="enquiryBox" method="POST" data-parsley-validate="true" v-on:submit.prevent="handelSubmit()">
<div class="modal-body brbottom-20">
<div class="clearfix">
<div class="col-lg-6">
<div class="form-group required">
<fieldset class="rating">
<input v-model="rating" type="radio" id="rating" name="rating" value="5" ><label class = "full" for="star5" title="Awesome">5</label>
<input v-model="rating" type="radio" id="rating" name="rating" value="4" ><label class="half" for="star4half" title="Pretty good">4</label>
</fieldset>
</div>
</div>
<div class="col-lg-6">
<div class="form-group required">
<label>Enquiry</label>
<textarea placeholder="Write your enquiry here" rows="7" id="enquiryDesc" name="enquiryDesc" class="form-control required" title="Desc" v-model="enquiryDesc" required="required"></textarea>
</div>
</div>
</div>
</div>
<div class="">
<button id="btn-submit-enquiry" class="btn whiteButton" type="submit">Post Enquiry</button>
</div>
</form>
This is the Vue.js script I am utilizing:
enquiryBox = new Vue({
el: "#enquiryBox",
data: {
rating: '',
enquiryDesc: '',
},
methods: {
handelSubmit: function(e) {
var vm = this;
data = {};
data['rating'] = this.rating;
data['enquiryDesc'] = this.enquiryDesc;
console.log(data);
$.ajax({
url: 'https://api/post/add_review/',
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if (e.status) {
alert("Success")
} else {
vm.response = e;
alert(" Failed")
}
}
});
return false;
}
},
});
Upon inspecting the response from the console.log(data)
{rating: "", enquiryDesc: "hello how are you"}
Despite my efforts, the rating value remains 5 and does not reflect any changes.