form.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\widgets\ActiveForm;
  4. use kartik\datetime\DateTimePicker;
  5. use app\widgets\CropperjsWidget;
  6. $form = ActiveForm::begin([
  7. 'id' => 'inquirer-form',
  8. 'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);
  9. ?>
  10. <input type="hidden" name="inquirer[id]" value="<?=$model->id?>">
  11. <div class="container-fluid">
  12. <div class="row">
  13. <div class="col">
  14. <?
  15. echo $form->field($model, 'text')->textInput([
  16. 'maxlength' => true,
  17. 'class' => 'form-control js-word-count-input',
  18. 'placeholder' => 'Вопрос',
  19. // 'id' => 'js-news-content'
  20. ])->label('Вопрос');
  21. ?>
  22. <div class="card">
  23. <div class="card-header">
  24. <h3 class="card-title">Варианты ответов</h3>
  25. </div>
  26. <div class="card-body">
  27. <?
  28. $answers = $model->getAnswers();
  29. foreach($answers as $item){
  30. ?>
  31. <div class="info-box answer">
  32. <span class="info-box-icon bg-info"><i class="far fa-thumbs-up"></i><br><span class="info-box-number-cnt"><?=$item->count?></span></span>
  33. <div class="info-box-content">
  34. <div class="input-group">
  35. <input type="text" class="form-control" value="<?=$item->text?>" name="Inquirer[text_answer][<?=$item->id?>]">
  36. <div class="input-group-append">
  37. <span class="btn btn-dark btn-flat" onclick="remove(this)"><b>-</b></span>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <?
  43. }
  44. ?>
  45. </div>
  46. <div class="card-footer">
  47. <div class="card-tools">
  48. <button type="button" class="btn btn-outline-primary" onclick="addanswer()"><b>+</b></button>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="form-group form-check">
  53. <?
  54. //($model->show == 'Y')?true:false,
  55. echo $form->field($model, 'show')->checkbox([
  56. 'class' => 'form-check-input',
  57. 'label' => 'Включить голосование',
  58. 'uncheck' => 'N',
  59. 'value' => 'Y',
  60. 'checked' => ($model->show == 'Y')?true:false
  61. ]);
  62. echo $form->field($model, 'active')->checkbox([
  63. 'class' => 'form-check-input',
  64. 'label' => 'Показывать',
  65. 'uncheck' => 'N',
  66. 'value' => 'Y',
  67. 'checked' => ($model->active == 'Y')?true:false
  68. ]);
  69. ?>
  70. </div>
  71. <div class="form-group">
  72. <?
  73. echo Html::submitButton('Сохранить', ['class' => 'btn btn-success']);
  74. ?>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. <script id="template-answer" type="text/template">
  80. <div class="info-box answer">
  81. <span class="info-box-icon bg-info"><i class="far fa-thumbs-up"></i></span>
  82. <div class="info-box-content">
  83. <div class="input-group">
  84. <input type="text" class="form-control" value="" name="Inquirer[text_new][]">
  85. <div class="input-group-append">
  86. <span class="btn btn-dark btn-flat" onclick="remove(this)"><b>-</b></span>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </script>
  92. <script>
  93. function addanswer(){
  94. el = document.getElementById('template-answer').innerHTML,
  95. $(el).appendTo($('.card-body'));
  96. }
  97. function remove(el){
  98. $(el).parent().closest('.answer').remove();
  99. }
  100. </script>
  101. <style>
  102. .info-box-number-cnt{
  103. position: absolute;
  104. bottom: 6px;
  105. font-size: 17px;
  106. }
  107. </style>
  108. <?
  109. ActiveForm::end();