on _create_mywork_help.html
*******************************
function generate_daily_time_list() {
var start_time = document.getElementById("id_start_time").value;
var interval = Number(document.getElementById("id_interval").value);
var daily = document.getElementById("id_daily");
//document.getElementById("id_daily").value = document.getElementById("id_daily").defaultValue;
document.getElementById("id_daily").innerHTML = "";
console.log(start_time);
console.log(interval);
console.log(daily);
const stime = String(start_time).split(" ");
const hm = stime[0].split(":");
console.log(hm[0]);
console.log(hm[1]);
var hr = Number(hm[0]);
var mins = String(hm[1]);
var pre = 0;
while (hr > 0){
pre = hr;
hr = hr - interval;
}
console.log(mins);
console.log('Deba');
var i = pre;
while (i < 24){
var option= document.createElement("option");
dtime = String(i).padStart(2, '0')+':'+mins;
//dtime_v = 'x'+String(i).padStart(2, '0')+mins;
console.log(dtime)
i = i+interval;
option.value= dtime;
option.text= dtime;
daily.add(option);
}
}
class myworkAction(workflows.Action):
start_time = forms.ChoiceField(label=_("Start Time"), required=False)
interval = forms.CharField(label=_("Hourly"),
required=False,
initial=24,
validators=[validate_scheduler_interval],
widget=forms.TextInput(
attrs={'placeholder': "Repeat interval must be in numbers only (Ex: 1 or 2)...",
'onkeyup': " $('#id_interval').val(document.getElementById('id_interval').value)",
'onchange': "generate_daily_time_list()"}))
daily = forms.MultipleChoiceField(label=_("Daily"), required=False)
class Meta:
name = _("mywork")
help_text_template = ("project/workloads/"
"_create_mywork_help.html")
def __init__(self, request, *args, **kwargs):
super(myworkAction, self).__init__(request,
*args, **kwargs)
start_time_list = populate_time_list()
self.fields['start_time'].choices = start_time_list
I want to take input 12:15 PM start time and interval e.g. 2
It should generate choices for “daily” filed as e.g. like 14:15 , 16:15
and it is generating, but when i select and submit it is giving error :
“Select a valid choice. 14:15 is not one of the available choices”. bcz self.fields[‘daily’].choices is blank list , which is not getting updated on the Python layer, however on UI shows all list.
It should update the choice list, but not update.