yii更新2字段下拉列表onchange

时间:2018-01-30 18:15:55

标签: php jquery yii

我正在使用带有AJAX请求的Yii 1从另一个下拉列表中更新下拉列表,我的步骤是:

  1. 点击货运代理(客户)
  2. 显示所选客户的状态= 6的所有操作
  3. 结果将显示在operation_id下拉列表中。
  4. 一切都好,有效。

    但现在我需要添加另一个步骤

    1. 根据所选客户更新截止日期。
    2. 和Customer表有条款字段,其中有一些数字,所以我需要将当前日期添加到该字段的结果中。

      例如,如果客户A的截止日期是20天后,则客户B的截止日期是20天后,依此类推。

      所以我可以得到那个,但问题是我怎么能这样做,我可以使用来自该控制器的相同动作(actionGetOperation)或不同的动作

      /** this is an action **/   public function actionGetOperation() {
          $data = Operation::model()->findAll('freight_forwarder_id=:freight_forwarder and status=6 and deleted !=1  and company_id  = :company ', 
                  array(
                      ':freight_forwarder' => (int) $_POST['Invoice'] ['freight_forwarder_id'] ,
                      ':company'=> Yii::app()->user->company , 
                  ));
          $data = CHtml::listData($data, 'id', 'operation_no');
          foreach ($data as $value => $operation_no) {
              echo CHtml::tag('option', array('value' => $value), CHtml::encode($operation_no), true);
          }
      }
      

      这就是行动

        <div class="col-md-4">
      
              <div class="form-group <?php echo $model->hasErrors('freight_forwarder_id') ? "has-error" : "" ?> ">
                  <?php echo $form->labelEx($model, 'freight_forwarder_id', array('class' => 'col-sm-5 control-label')); ?>
      
                  <div class="col-sm-7">
                      <?php
                      $options = array(
                          'id' => 'freight_forwarder_id',
                          'class' => 'form-control input-sm',
                          'empty' => '',
                          'ajax' => array(
                              'type' => 'POST',
                              'url' => CController::createUrl('Invoice/GetOperation'),
                               'update' => '#' . CHtml::activeId($model, 'operation_id'),Invoice_operation_id
                              //'update' => '#Invoice_operation_id ,#Invoice_due_date',
                          )
                      );
      
                      echo $form->dropDownList($model, 'freight_forwarder_id', CHtml::listData(Freight_forwarder::model()->allFreight_forwarder($contact_category=='customer'? 1 : 2), 'id', 'name'), $options);
                      ?>
                  </div>
              </div> 
      
      
              <div class="form-group <?php echo $model->hasErrors('operation_id') ? "has-error" : "" ?> "  >
                  <?php echo $form->labelEx($model, 'operation_id', array('class' => 'col-sm-4 control-label')); ?>
                  <div class="col-sm-8"><?php echo $form->dropDownList($model, 'operation_id', array(), array('class' => 'form-control input-sm')); ?> </div>
              </div>
      
      
              <div class="form-group <?php echo $model->hasErrors('due_date') ? "has-error" : "" ?> ">
                  <?php echo $form->labelEx($model, 'due_date', array('class' => 'col-sm-5 control-label')); ?>
                  <div class="col-sm-7">
                      <?php
                      $this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => CHtml::activeName($model, 'due_date'), 'value' => date("Y-m-d"),
                          'options' => array('firstDay' => 6, 'dateFormat' => 'yy-mm-dd',),
                          'htmlOptions' => array('class' => 'form-control input-sm'),
                      ));
                      ?> 
                  </div>
              </div>
      
          </div>
      

0 个答案:

没有答案