Alloy-ui 多个日期选择器将选择发送到其他输入

Alloy-ui multiple datepicker send selection to other input

我有由 div id="trigger" 触发的 AlloyUi 日期选择器,但我想显示在隐藏 input id="dates".

中选择的日期

YUI().use('aui-datepicker', function(Y) {
    var output = Y.one('#dates');
    var multidatepicker = new Y.DatePicker(
      {
        mask: '%Y-%m-%d',
        trigger: '#startdate',
        calendar: {
          selectionMode: 'multiple',
          on: {
            dateClick: function(event) {
                output.set('value', Y.Date.format(event.date,{format:multidatepicker.get('mask')}));
                }
          }
        },
        popover: {
          zIndex: 10
        },
        panes: 2
        
      })
  });
<link href="http://cdn.alloyui.com/3.0.1/aui-css/css/bootstrap.min.css" rel="stylesheet" />
<script src="http://cdn.alloyui.com/3.0.1/aui/aui-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="trigger">        
          <div class='col-md-4'>      
            <div class="form-group">
              <label class="control-label" for="email">Start Date</label>
              <div class='input-group date' id=''>
                <input type='text' data-format="dd/MM/yyyy" id="startdate" class="form-control multidate" />
                <span class="input-group-addon">
                  <span class="glyphicon glyphicon-calendar"></span>
                </span>
              </div>
            </div>
          </div>
          <input id="dates" class="form-control" style="display:hidden"></input>
          <div class='col-md-4'>
            <div class="form-group">
              <label class="control-label" for="email">End Date</label>
              <div class='input-group date' id=''>
                <input type='text' data-format="dd/MM/yyyy" id="enddate" class="form-control multidate" />
                <span class="input-group-addon">
                  <span class="glyphicon glyphicon-calendar"></span>
                </span>
              </div>
            </div>
          </div>
          </div>

我找到了一个解决方案 here,但它只将一个日期传递给输入。我需要传递用户选择的日期范围。 有什么想法吗?

可以将#startdatevalue属性复制到#datesvalue属性中after点击日期:

after: {
    dateClick: function(event) {
        output.set('value', 
            Y.one(multidatepicker.get('trigger')).get('value'));
    }
}

这是您的代码的可运行示例:

YUI().use('aui-datepicker', function(Y) {
  var output = Y.one('#dates');
  var multidatepicker = new Y.DatePicker({
    mask: '%Y-%m-%d',
    trigger: '#startdate',
    calendar: {
      selectionMode: 'multiple',
      after: {
        dateClick: function(event) {
          output.set('value', Y.one(multidatepicker.get('trigger')).get('value'));
        }
      }
    },
    popover: {
      zIndex: 1000
    },
    panes: 2

  })
});
<script src="https://cdn.rawgit.com/stiemannkj1/701826667a70997013605edcd37e92a6/raw/469fe1ae297e72a5a80eb9015003b7b04eac735e/alloy-ui-3.0.1_aui_aui-min.js"></script>
<link href="https://cdn.rawgit.com/stiemannkj1/90be22de7f48c729b443af14796d91d3/raw/a9f35ceedfac7fc0559b121bed105eaf80f10bf2/aui-css_css_bootstrap.min.css" rel="stylesheet"></link>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="trigger">
  <div class='col-md-4'>
    <div class="form-group">
      <label class="control-label" for="email">Start Date</label>
      <div class='input-group date' id=''>
        <input type='text' data-format="dd/MM/yyyy" id="startdate" class="form-control multidate" />
        <span class="input-group-addon">
                  <span class="glyphicon glyphicon-calendar"></span>
        </span>
      </div>
    </div>
  </div>
  <input id="dates" class="form-control" style="display:hidden"></input>
  <div class='col-md-4'>
    <div class="form-group">
      <label class="control-label" for="email">End Date</label>
      <div class='input-group date' id=''>
        <input type='text' data-format="dd/MM/yyyy" id="enddate" class="form-control multidate" />
        <span class="input-group-addon">
                  <span class="glyphicon glyphicon-calendar"></span>
        </span>
      </div>
    </div>
  </div>
</div>