A reference to another question saw in the stack overflow.
I checked for a solution like this but haven't succeeded yet.
<div class="form-group">
<label>Working Hours :</label>
<div v-for="value in day" class="checkboxFour"<input type="checkbox" id="need" value="value.val" v-model="value.selected" style="width: 10%!important;">
<p>FROM</p>
<label for="need" style=" width: 20%!important;">{{value.name}}</label>
<input id="value.from" type="time" v-model="value.from" name="value.from" style="width: 30%!important;">
<p>TO</p>
<input id="value.to" type="time" v-model="value.to" name="value.to" style="width: 30%!important;">
<br>
</div>
</div>
My vue js code for the same is
work = new Vue({
el: "#work",
data: {
data: [],
day:[
{name:"Sunday",val:1},
{name:"Monday",val:2},
{name:"Tuesday",val:3},
{name:"Wednesday",val:4},
{name:"Thursday",val:5},
{name:"Friday",val:6},
{name:"Saturday",val:7}
],
string:'',
},
methods: {
wrkSubmit: function(e){
var arr = [];
this.day.map(function(v,i) {
console.log(v.selected == true);
if(v.selected == true){
arr.push(v.val+'&'+v.from+'&'+v.to);
}
});
this.string = arr.join(',');
var vm = this;
data = {};
data['wrk_list'] = this.string;
$.ajax({
url: 'http://127.0.0.1:8000/add/workhour/',
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if(e.status){
alert("Success")
} else {
alert(" Failed")
}
}
});
return false;
},
}
If I try this code. I need to select working hours separately for each day I am selecting. Rather I need to choose a time first and hence use that working hour for all the days I am choosing. Also, give an edit option if the user needs to change time. A solution to this problem has given there, but it is not based on the code given above.
Is it possible to have a solution as such? Select a working hour at first and then use it for all the days selecting ie. checkbox, and change values if needed.
Just for experimenting purpose. If it is possible please help me.
You need to assign value of your data array when change event of your checkbox is clicked,
Below is working code,
Hope this helps. :)
The answer above covers pretty much the problem, the issues is that if you change your default hour, the selected days will not update unless you uncheck it and check it again, but here are Watchers to the rescue, watch (doh) when the default values changes, then update the selected days.
(open the snippet in full page if you can't see it)