Advertisement
penoace

tes

Feb 1st, 2016
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.16 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. use yii\helpers\Html;
  5.  
  6. use yii\bootstrap\ActiveForm;
  7. //use yii\widgets\ActiveForm;
  8. //use kartik\widgets\ActiveForm;
  9. use wbraganca\dynamicform\DynamicFormWidget;
  10. use app\models\Kompetensi;
  11. use yii\web\JsExpression;
  12. use yii\helpers\ArrayHelper;
  13. use yii\jui\AutoComplete;
  14. use kartik\widgets\Select2;
  15.  
  16. $kompetensi = ArrayHelper::map(Kompetensi::find()->all(), 'id_kompetensi','judul');
  17.  
  18.   $data = app\models\USERINFO::find()
  19.     ->select([ 'name as  label','ID as value'])
  20.     ->asArray()
  21.     ->all();
  22.  
  23. //print_r($data);
  24. /* @var $this yii\web\View */
  25.  
  26. /* @var $modelprogram app\modules\yii2extensions\models\Customer */
  27.  
  28. /* @var $modelspeserta app\modules\yii2extensions\models\Address */
  29.  
  30.  
  31. $js = '
  32.  
  33. jQuery(".dynamicform_wrapper").on("afterInsert", function(e, item) {
  34.  
  35.    jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {
  36.  
  37.        jQuery(this).html("Peserta: " + (index + 1))
  38.  
  39.    });
  40.  
  41. });
  42.  
  43.  
  44. jQuery(".dynamicform_wrapper").on("afterDelete", function(e) {
  45.  
  46.    jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {
  47.  
  48.        jQuery(this).html("Peserta: " + (index + 1))
  49.  
  50.    });
  51.  
  52. });
  53.  
  54. ';
  55.  
  56.  
  57. $this->registerJs($js);
  58.  
  59. ?>
  60.  
  61.  
  62. <div class="customer-form">
  63.  
  64.  
  65.     <?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
  66.  
  67.     <div class="row">
  68.  
  69.         <div class="col-sm-6">
  70.  
  71.             <?= $form->field($modelprogram, 'id_kompetensi')->dropDownList($kompetensi,['style'=>'width:500px']) ?>
  72.  
  73.         </div>
  74.  
  75.         <div class="col-sm-6">
  76.  
  77.             <?= $form->field($modelprogram, 'j_peserta')->textInput(['maxlength' => true]) ?>
  78.  
  79.         </div>
  80.  
  81.     </div>
  82.  
  83.  
  84.     <div class="padding-v-md">
  85.  
  86.         <div class="line line-dashed"></div>
  87.  
  88.     </div>
  89.  
  90.     <?php DynamicFormWidget::begin([
  91.  
  92.         'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
  93.  
  94.         'widgetBody' => '.container-items', // required: css class selector
  95.  
  96.         'widgetItem' => '.item', // required: css class
  97.  
  98.         'limit' => 4, // the maximum times, an element can be cloned (default 999)
  99.  
  100.         'min' => 0, // 0 or 1 (default 1)
  101.  
  102.         'insertButton' => '.add-item', // css class
  103.  
  104.         'deleteButton' => '.remove-item', // css class
  105.  
  106.         'model' => $modelspeserta[0],
  107.  
  108.         'formId' => 'dynamic-form',
  109.         //'autocompleteDatasource'=>$data,
  110.        // 'uniqueClass'=>'id_karyawan',
  111.         'formFields' => [
  112.  
  113.             'id_karyawan',
  114.  
  115.             'hari',
  116.  
  117.            // 'address_line2',
  118.  
  119.           //  'city',
  120.  
  121.           //  'state',
  122.  
  123.           //  'postal_code',
  124.  
  125.         ],
  126.  
  127.     ]); ?>
  128.  
  129.     <div class="panel panel-default">
  130.  
  131.         <div class="panel-heading">
  132.  
  133.             <i class="fa fa-envelope"></i> Peserta
  134.  
  135.             <button type="button" class="pull-right add-item btn btn-success btn-xs"><i class="fa fa-plus"></i> Tambah Peserta</button>
  136.  
  137.             <div class="clearfix"></div>
  138.  
  139.         </div>
  140.  
  141.         <div class="panel-body container-items"><!-- widgetContainer -->
  142.  
  143.             <?php foreach ($modelspeserta as $index => $modelpeserta): ?>
  144.  
  145.                 <div class="item panel panel-default"><!-- widgetBody -->
  146.  
  147.                     <div class="panel-heading">
  148.  
  149.                         <span class="panel-title-address">Peserta: <?= ($index + 1) ?></span>
  150.  
  151.                         <button type="button" class="pull-right remove-item btn btn-danger btn-xs"><i class="fa fa-minus"></i></button>
  152.  
  153.                         <div class="clearfix"></div>
  154.  
  155.                     </div>
  156.  
  157.                     <div class="panel-body">
  158.  
  159.                         <?php
  160.  
  161.                             // necessary for update action.
  162.  
  163.                             if (!$modelpeserta->isNewRecord) {
  164.  
  165.                                 echo Html::activeHiddenInput($modelpeserta, "[{$index}]id");
  166.  
  167.                             }
  168.  
  169.                         ?>
  170.                                              
  171.                        
  172.                        
  173.                           <?php
  174.    
  175.                     echo $form->field($modelpeserta, "[{$index}]id_karyawan")->widget(Select2::classname(), [
  176.                     'data' => $data,
  177.                    // 'options' => ['placeholder' => 'Select a state ...'],
  178.                     'pluginOptions' => [
  179.                         'allowClear' => true
  180.                     ],
  181.                 ]);
  182.                        ?>
  183.  
  184.                         <div class="row">
  185.  
  186.                             <div class="col-sm-6">
  187.  
  188.                                 <?= $form->field($modelpeserta, "[{$index}]hari")->textInput(['maxlength' => true]) ?>
  189.  
  190.                             </div>
  191.  
  192.                            
  193.  
  194.                         </div><!-- end:row -->
  195.  
  196.  
  197.  
  198.  
  199.  
  200.                     </div>
  201.  
  202.                 </div>
  203.  
  204.             <?php endforeach; ?>
  205.  
  206.         </div>
  207.  
  208.     </div>
  209.  
  210.     <?php DynamicFormWidget::end(); ?>
  211.  
  212.  
  213.     <div class="form-group">
  214.  
  215.         <?= Html::submitButton($modelpeserta->isNewRecord ? 'Create' : 'Update', ['class' => 'btn btn-primary']) ?>
  216.  
  217.     </div>
  218.  
  219.  
  220.     <?php ActiveForm::end(); ?>
  221.  
  222.  
  223. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement