예제 #1
0
파일: ActiveForm.php 프로젝트: Liv1020/cms
 /**
  * @param $model
  * @param $attribute
  * @param array $config
  * @param array $fieldOptions
  * @return ActiveField the created ActiveField object
  */
 public function fieldInputInt($model, $attribute, $config = [], $fieldOptions = [])
 {
     //Html::addCssClass($config, "sx-input-int");
     $config['class'] = ArrayHelper::getValue($config, 'class') . "form-control sx-input-int";
     /**
     *  'initval' => 3.00,
        'min' => 0,
        'max' => 100,
        'step' => 0.1,
        'decimals' => 2,
        'boostat' => 5,
        'maxboostedstep' => 10,
        'prefix' => '$',
     */
     $defaultOptions = ['pluginOptions' => ['max' => 9999999999]];
     $pluginOptions = ArrayHelper::merge($defaultOptions, (array) $config);
     //return $this->field($model, $attribute, $fieldOptions)->textInput($config);
     return $this->field($model, $attribute, $fieldOptions)->widget(\kartik\touchspin\TouchSpin::className(), $pluginOptions);
 }
예제 #2
0
파일: _form.php 프로젝트: abutouq/video
?>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6"><?php 
echo $form->field($model, 'username')->textInput(['maxlength' => true]);
?>
</div>
        <div class="row">
            <div class="col-lg-2"> <?php 
echo $form->field($model, 'password')->passwordInput(['maxlength' => true]);
?>
</div>
            <div class="col-lg-3"> <?php 
echo $form->field($model, 'grace_time')->widget(TouchSpin::className(), ['name' => 'grace_time', 'pluginOptions' => ['postfix' => 'days', 'min' => 2, 'max' => 30]]);
?>
</div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6"> <?php 
echo $form->field($model, 'full_name')->textInput(['maxlength' => true]);
?>
</div>
        <div class="col-lg-6"> <?php 
echo $form->field($contactModel, 'email')->textInput();
?>
</div>
    </div>
예제 #3
0
 /**
  * Create ActiveForm widget.
  *
  * @param \yii\widgets\ActiveForm $form
  * @param \yii\db\ActiveRecord $model Model
  * @param string $attribute Model attribute
  */
 public function createWidget($form, $model, $attribute)
 {
     $widget = $this->getAttributeWidget($model, $attribute);
     $tableSchema = $model->getTableSchema();
     switch ($widget) {
         case 'widget':
             echo $this->createField($form, $model, $attribute, [], 'widget');
             break;
         case 'wysiwyg':
             $options = ['widgetClass' => RedactorWidget::className(), 'settings' => ['minHeight' => 200, 'plugins' => ['video', 'fullscreen']]];
             if ($this->redactorImageUpload === true) {
                 $imageOptions = ['settings' => ['imageManagerJson' => Url::to(['model/redactor-list', 'name' => $this->getModelName($model), 'attr' => $attribute]), 'imageUpload' => Url::to(['model/redactor-upload', 'name' => $this->getModelName($model), 'attr' => $attribute]), 'imageUploadErrorCallback' => new JsExpression('function(json) { alert(json.error); }'), 'plugins' => ['imagemanager']]];
                 $options = ArrayHelper::merge($options, $imageOptions);
             }
             if ($this->redactorFileUpload === true) {
                 $fileOptions = ['settings' => ['fileManagerJson' => Url::to(['model/redactor-list', 'name' => $this->getModelName($model), 'attr' => $attribute, 'type' => 'file']), 'fileUpload' => Url::to(['model/redactor-upload', 'name' => $this->getModelName($model), 'attr' => $attribute, 'type' => 'file']), 'fileUploadErrorCallback' => new JsExpression('function(json) { alert(json.error); }'), 'plugins' => ['filemanager']]];
                 $options = ArrayHelper::merge($options, $fileOptions);
             }
             echo $this->createField($form, $model, $attribute, $options, 'widget');
             break;
         case 'date':
             $options = ['widgetClass' => TimePicker::className(), 'mode' => 'date', 'clientOptions' => ['dateFormat' => 'yy-mm-dd']];
             echo $this->createField($form, $model, $attribute, $options, 'widget');
             break;
         case 'time':
             $options = ['widgetClass' => TimePicker::className(), 'mode' => 'time', 'clientOptions' => ['timeFormat' => 'HH:mm:ss', 'showSecond' => true]];
             echo $this->createField($form, $model, $attribute, $options, 'widget');
             break;
         case 'datetime':
             $options = ['widgetClass' => TimePicker::className(), 'mode' => 'datetime', 'clientOptions' => ['dateFormat' => 'yy-mm-dd', 'timeFormat' => 'HH:mm:ss', 'showSecond' => true]];
             echo $this->createField($form, $model, $attribute, $options, 'widget');
             break;
         case 'select':
             $options = ['options' => ['placeholder' => Yii::t('ycm', 'Choose {name}', ['name' => $model->getAttributeLabel($attribute)]), 'width' => '100%'], 'pluginOptions' => ['allowClear' => true, 'width' => '100%'], 'data' => ['' => '']];
             echo $this->createField($form, $model, $attribute, $options, 'select');
             break;
         case 'selectMultiple':
             $options = ['options' => ['multiple' => true, 'placeholder' => Yii::t('ycm', 'Choose {name}', ['name' => $model->getAttributeLabel($attribute)]), 'width' => '100%']];
             echo $this->createField($form, $model, $attribute, $options, 'select');
             break;
         case 'image':
             $options = [];
             if (!$model->isNewRecord && !empty($model->{$attribute})) {
                 $className = StringHelper::basename($model->className());
                 $inputName = $className . '[' . $attribute . '_delete]';
                 $inputId = strtolower($className . '-' . $attribute . '_delete');
                 $url = $this->getAttributeUrl($this->getModelName($model), $attribute, $model->{$attribute});
                 ob_start();
                 echo '<div class="checkbox"><label for="' . $inputId . '">
                     <input type="checkbox" name="' . $inputName . '" id="' . $inputId . '" value="delete"> ' . Yii::t('ycm', 'Delete image') . '
                 </label></div>';
                 Modal::begin(['size' => Modal::SIZE_LARGE, 'header' => '<h4>' . Yii::t('ycm', 'Preview image') . '</h4>', 'toggleButton' => ['label' => Yii::t('ycm', 'Preview image'), 'class' => 'btn btn-info btn-sm']]);
                 echo Html::img($url, ['class' => 'modal-image']);
                 Modal::end();
                 $html = ob_get_clean();
                 $options['hint'] = $html;
             }
             echo $this->createField($form, $model, $attribute, $options, 'fileInput');
             break;
         case 'file':
             $options = [];
             if (!$model->isNewRecord && !empty($model->{$attribute})) {
                 $className = StringHelper::basename($model->className());
                 $inputName = $className . '[' . $attribute . '_delete]';
                 $inputId = strtolower($className . '-' . $attribute . '_delete');
                 $url = $this->getAttributeUrl($this->getModelName($model), $attribute, $model->{$attribute});
                 $html = '<div class="checkbox"><label for="' . $inputId . '">
                     <input type="checkbox" name="' . $inputName . '" id="' . $inputId . '" value="delete"> ' . Yii::t('ycm', 'Delete file') . '
                 </label></div>';
                 $html .= Html::a(Yii::t('ycm', 'Download file'), $url, ['class' => 'btn btn-info btn-sm']);
                 $options['hint'] = $html;
             }
             echo $this->createField($form, $model, $attribute, $options, 'fileInput');
             break;
         case 'text':
             $options = ['maxlength' => $tableSchema->columns[$attribute]->size];
             echo $this->createField($form, $model, $attribute, $options, 'textInput');
             break;
         case 'integer':
             $options = ['widgetClass' => TouchSpin::className(), 'pluginOptions' => ['min' => -PHP_INT_MAX, 'max' => PHP_INT_MAX]];
             echo $this->createField($form, $model, $attribute, $options, 'widget');
             break;
         case 'hidden':
             $options = ['maxlength' => $tableSchema->columns[$attribute]->size];
             $options = $this->getAttributeOptions($attribute, $options);
             echo Html::activeHiddenInput($model, $attribute, $options);
             break;
         case 'password':
             $options = ['maxlength' => $tableSchema->columns[$attribute]->size];
             echo $this->createField($form, $model, $attribute, $options, 'passwordInput');
             break;
         case 'textarea':
             $options = ['rows' => 6];
             echo $this->createField($form, $model, $attribute, $options, 'textarea');
             break;
         case 'radio':
             echo $this->createField($form, $model, $attribute, [], 'radio');
             break;
         case 'boolean':
         case 'checkbox':
             echo $this->createField($form, $model, $attribute, [], 'checkbox');
             break;
         case 'dropdown':
             $options = ['prompt' => Yii::t('ycm', 'Choose {name}', ['name' => $model->getAttributeLabel($attribute)])];
             echo $this->createField($form, $model, $attribute, $options, 'dropDownList');
             break;
         case 'listbox':
             $options = ['prompt' => ''];
             echo $this->createField($form, $model, $attribute, $options, 'listBox');
             break;
         case 'checkboxList':
             echo $this->createField($form, $model, $attribute, [], 'checkboxList');
             break;
         case 'radioList':
             echo $this->createField($form, $model, $attribute, [], 'radioList');
             break;
         case 'disabled':
             $options = ['maxlength' => $tableSchema->columns[$attribute]->size, 'readonly' => true];
             echo $this->createField($form, $model, $attribute, $options, 'textInput');
             break;
         case 'hide':
             break;
             // Special type - model relation
         // Special type - model relation
         case 'relation':
             $relation = $model->getRelation($attribute);
             $options = ['widgetClass' => Select2::className(), 'data' => ModelHelper::getSelectChoices(new $relation->modelClass()), 'hideSearch' => false, 'options' => ['multiple' => $relation->multiple, 'placeholder' => 'Select...'], 'pluginOptions' => ['allowClear' => true]];
             echo $this->createField($form, $model, $attribute, $options, 'widget');
             break;
             // Special type - field with enum values from DB
         // Special type - field with enum values from DB
         case 'enumerate':
             $options = ['widgetClass' => Select2::className(), 'data' => ModelHelper::getEnumChoices($model, $attribute), 'options' => ['placeholder' => 'Select...']];
             echo $this->createField($form, $model, $attribute, $options, 'widget');
             break;
         default:
             $options = $this->getAttributeOptions($attribute);
             echo $form->field($model, $attribute)->{$widget}($options);
             break;
     }
 }