英文:
How to select date every 2 weeks for a date picker
问题
This is your code with the translated comments:
<script type="text/javascript">
gform.addFilter('gform_datepicker_options_pre_init', function(optionsObj, formId, fieldId) {
if (formId == 3 && fieldId == 45) {
optionsObj.minDate = 0;
optionsObj.beforeShowDay = function(date) {
var enabledDays = ['05/22/2023', '06/05/2023', '06/19/2023', '07/03/2023', '07/17/2023', '08/14/2023', '08/28/2023', '09/11/2023', '09/25/2023', '10/09/2023'],
currentDate = jQuery.datepicker.formatDate('mm/dd/yy', date),
day = date.getDay();
return [(enabledDays.indexOf(currentDate) != -1)];
};
}
return optionsObj;
} );
</script>
Note: The code you provided doesn't have any specific translation needs as it's primarily written in English. If you have any specific questions or requests related to this code, please feel free to ask.
英文:
I have this code, it selects every Monday(every 2 weeks) for a date picker, this code is works for me, is there a simple way to auto select the dates instead of manually write the date for each day?
<script type="text/javascript">
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 3 && fieldId == 45 ) {
optionsObj.minDate = 0;
optionsObj.beforeShowDay = function(date) {
var enabledDays = ['05/22/2023', '06/05/2023', '06/19/2023', '07/03/2023', '07/17/2023', '08/14/2023', '08/28/2023', '09/11/2023', '09/25/2023', '10/09/2023'],
currentDate = jQuery.datepicker.formatDate('mm/dd/yy', date),
day = date.getDay();
return [(enabledDays.indexOf(currentDate) != -1)];
};
}
return optionsObj;
} );
</script>
答案1
得分: 1
You could give the option an array as a value
console.log(value[0]) // will return 1
console.log(value[3]) // will return 4
console.log(value) // will return [1,2,3,4,5,6]
<select name="weekly_date" id="weekly_date_value" onChange="SetFieldProperty('rdaWeeklyDateGField', this.value);">
<option value="">Choose Day</option>
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
<option value="[1,2,3,4,5,6]">except sunday</option>
</select>
英文:
You could give the option an array as a value
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
console.log(value[0]) // will return 1
console.log(value[3]) // will return 4
console.log(value) // will return [1,2,3,4,5,6]
<!-- language: lang-html -->
<select name="weekly_date" id="weekly_date_value" onChange="SetFieldProperty('rdaWeeklyDateGField', this.value);">
<option value="">Choose Day</option>
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
<option value="[1,2,3,4,5,6]">except sunday</option>
</select>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论