Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use yii\helpers\Html;
- use yii\bootstrap\ActiveForm;
- //use yii\widgets\ActiveForm;
- //use kartik\widgets\ActiveForm;
- use wbraganca\dynamicform\DynamicFormWidget;
- use app\models\Kompetensi;
- use yii\web\JsExpression;
- use yii\helpers\ArrayHelper;
- use yii\jui\AutoComplete;
- use kartik\widgets\Select2;
- $kompetensi = ArrayHelper::map(Kompetensi::find()->all(), 'id_kompetensi','judul');
- $data = app\models\USERINFO::find()
- ->select([ 'name as label','ID as value'])
- ->asArray()
- ->all();
- //print_r($data);
- /* @var $this yii\web\View */
- /* @var $modelprogram app\modules\yii2extensions\models\Customer */
- /* @var $modelspeserta app\modules\yii2extensions\models\Address */
- $js = '
- jQuery(".dynamicform_wrapper").on("afterInsert", function(e, item) {
- jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {
- jQuery(this).html("Peserta: " + (index + 1))
- });
- });
- jQuery(".dynamicform_wrapper").on("afterDelete", function(e) {
- jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {
- jQuery(this).html("Peserta: " + (index + 1))
- });
- });
- ';
- $this->registerJs($js);
- ?>
- <div class="customer-form">
- <?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
- <div class="row">
- <div class="col-sm-6">
- <?= $form->field($modelprogram, 'id_kompetensi')->dropDownList($kompetensi,['style'=>'width:500px']) ?>
- </div>
- <div class="col-sm-6">
- <?= $form->field($modelprogram, 'j_peserta')->textInput(['maxlength' => true]) ?>
- </div>
- </div>
- <div class="padding-v-md">
- <div class="line line-dashed"></div>
- </div>
- <?php DynamicFormWidget::begin([
- 'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
- 'widgetBody' => '.container-items', // required: css class selector
- 'widgetItem' => '.item', // required: css class
- 'limit' => 4, // the maximum times, an element can be cloned (default 999)
- 'min' => 0, // 0 or 1 (default 1)
- 'uniqueClass'=>'Class_id_karyawan',
- 'autocompleteDatasource'=>"<datasource for autocomplete in array>",
- 'insertButton' => '.add-item', // css class
- 'deleteButton' => '.remove-item', // css class
- 'model' => $modelspeserta[0],
- 'formId' => 'dynamic-form',
- //'autocompleteDatasource'=>$data,
- // 'uniqueClass'=>'id_karyawan',
- 'formFields' => [
- 'id_karyawan',
- 'hari',
- // 'address_line2',
- // 'city',
- // 'state',
- // 'postal_code',
- ],
- ]); ?>
- <div class="panel panel-default">
- <div class="panel-heading">
- <i class="fa fa-envelope"></i> Peserta
- <button type="button" class="pull-right add-item btn btn-success btn-xs"><i class="fa fa-plus"></i> Tambah Peserta</button>
- <div class="clearfix"></div>
- </div>
- <div class="panel-body container-items"><!-- widgetContainer -->
- <?php foreach ($modelspeserta as $index => $modelpeserta): ?>
- <div class="item panel panel-default"><!-- widgetBody -->
- <div class="panel-heading">
- <span class="panel-title-address">Peserta: <?= ($index + 1) ?></span>
- <button type="button" class="pull-right remove-item btn btn-danger btn-xs"><i class="fa fa-minus"></i></button>
- <div class="clearfix"></div>
- </div>
- <div class="panel-body">
- <?php
- // necessary for update action.
- if (!$modelpeserta->isNewRecord) {
- echo Html::activeHiddenInput($modelpeserta, "[{$index}]id");
- }
- ?>
- <?php
- echo $form->field($modelpeserta, "[{$index}]id_karyawan")->->label(false)->textInput(['class' =>'Class_id_karyawan']) ?>
- ?>
- <div class="row">
- <div class="col-sm-6">
- <?= $form->field($modelpeserta, "[{$index}]hari")->textInput(['maxlength' => true]) ?>
- </div>
- </div><!-- end:row -->
- </div>
- </div>
- <?php endforeach; ?>
- </div>
- </div>
- <?php DynamicFormWidget::end(); ?>
- <div class="form-group">
- <?= Html::submitButton($modelpeserta->isNewRecord ? 'Create' : 'Update', ['class' => 'btn btn-primary']) ?>
- </div>
- <?php ActiveForm::end(); ?>
- </div>
Add Comment
Please, Sign In to add comment