选择日期选择器中的每两周日期。

huangapple go评论65阅读模式
英文:

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?

&lt;script type=&quot;text/javascript&quot;&gt;

 gform.addFilter( &#39;gform_datepicker_options_pre_init&#39;, function( optionsObj, formId, fieldId ) {

 if ( formId == 3 &amp;&amp; fieldId == 45 ) {
 optionsObj.minDate = 0;
 optionsObj.beforeShowDay = function(date) {
            var enabledDays = [&#39;05/22/2023&#39;, &#39;06/05/2023&#39;, &#39;06/19/2023&#39;, &#39;07/03/2023&#39;, &#39;07/17/2023&#39;, &#39;08/14/2023&#39;, &#39;08/28/2023&#39;, &#39;09/11/2023&#39;, &#39;09/25/2023&#39;, &#39;10/09/2023&#39;],
                currentDate = jQuery.datepicker.formatDate(&#39;mm/dd/yy&#39;, date),
                day = date.getDay();
  
            return [(enabledDays.indexOf(currentDate) != -1)];
        };
 }
 return optionsObj;
 } );

&lt;/script&gt;

答案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 -->

&lt;select name=&quot;weekly_date&quot; id=&quot;weekly_date_value&quot; onChange=&quot;SetFieldProperty(&#39;rdaWeeklyDateGField&#39;, this.value);&quot;&gt;
  &lt;option value=&quot;&quot;&gt;Choose Day&lt;/option&gt;
  &lt;option value=&quot;0&quot;&gt;Sunday&lt;/option&gt;
  &lt;option value=&quot;1&quot;&gt;Monday&lt;/option&gt;
  &lt;option value=&quot;2&quot;&gt;Tuesday&lt;/option&gt;
  &lt;option value=&quot;3&quot;&gt;Wednesday&lt;/option&gt;
  &lt;option value=&quot;4&quot;&gt;Thursday&lt;/option&gt;
  &lt;option value=&quot;5&quot;&gt;Friday&lt;/option&gt;
  &lt;option value=&quot;6&quot;&gt;Saturday&lt;/option&gt;
  &lt;option value=&quot;[1,2,3,4,5,6]&quot;&gt;except sunday&lt;/option&gt;
&lt;/select&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月14日 21:12:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247651.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定