Ejemplo n.º 1
0
 /**
  * Renders the select2 field
  */
 public function renderField()
 {
     list($name, $id) = $this->resolveNameID();
     $this->htmlOptions = WhHtml::defaultOption('id', $id, $this->htmlOptions);
     $this->htmlOptions = WhHtml::defaultOption('name', $name, $this->htmlOptions);
     if ($this->hasModel()) {
         echo $this->asDropDownList ? CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : CHtml::activeHiddenField($this->model, $this->attribute);
     } else {
         echo $this->asDropDownList ? CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions) : CHtml::hiddenField($this->name, $this->value);
     }
 }
Ejemplo n.º 2
0
 /**
  * Renders the multiselect field
  */
 public function renderField()
 {
     list($name, $id) = $this->resolveNameID();
     $this->htmlOptions = WhHtml::defaultOption('id', $id, $this->htmlOptions);
     $this->htmlOptions = WhHtml::defaultOption('name', $name, $this->htmlOptions);
     if ($this->hasModel()) {
         echo WhHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo WhHtml::textField($this->name, $this->value, $this->htmlOptions);
     }
 }
Ejemplo n.º 3
0
 /**
  * Renders the input file field
  */
 public function renderField()
 {
     list($name, $id) = $this->resolveNameID();
     $this->htmlOptions = WhHtml::defaultOption('id', $id, $this->htmlOptions);
     $this->htmlOptions = WhHtml::defaultOption('name', $name, $this->htmlOptions);
     $this->htmlOptions['data-url'] = $this->uploadAction;
     if ($this->hasModel()) {
         echo CHtml::activeFileField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::fileField($name, $this->value, $this->htmlOptions);
     }
 }
Ejemplo n.º 4
0
 /**
  * Renders the field
  */
 public function renderField()
 {
     list($name, $id) = $this->resolveNameID();
     $this->htmlOptions = WhHtml::defaultOption('id', $id, $this->htmlOptions);
     $this->htmlOptions = WhHtml::defaultOption('name', $name, $this->htmlOptions);
     echo '<span class="bootstrap-timepicker">';
     if ($this->hasModel()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions, array('style' => 'width:100%'));
     }
     echo '</span>';
 }
Ejemplo n.º 5
0
 /**
  * Renders field
  */
 public function renderField()
 {
     list($name, $id) = $this->resolveNameID();
     $this->htmlOptions = WhHtml::defaultOption('id', $id, $this->htmlOptions);
     $this->htmlOptions = WhHtml::defaultOption('name', $name, $this->htmlOptions);
     $tagOptions = $this->htmlOptions;
     $tagOptions['id'] = 'aceEditor_' . $tagOptions['id'];
     echo WhHtml::tag('div', $tagOptions);
     $this->htmlOptions['style'] = 'display:none';
     if ($this->hasModel()) {
         echo WhHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo WhHtml::textArea($name, $this->value, $this->htmlOptions);
     }
     $this->htmlOptions = $tagOptions;
 }
Ejemplo n.º 6
0
 /**
  * Sets up default options for the plugin
  * - thanks https://github.com/anggiaj
  */
 protected function initDefaultOptions()
 {
     list($name, $id) = $this->resolveNameID();
     $this->htmlOptions = WhHtml::defaultOption('id', $id, $this->htmlOptions);
     $this->htmlOptions = WhHtml::defaultOption('name', $name, $this->htmlOptions);
     $this->defaultOptions = array('request' => array('endpoint' => $this->uploadAction, 'inputName' => $name), 'validation' => $this->getValidator(), 'messages' => array('typeError' => Yii::t('zii', '{file} has an invalid extension. Valid extension(s): {extensions}.'), 'sizeError' => Yii::t('zii', '{file} is too large, maximum file size is {sizeLimit}.'), 'minSizeError' => Yii::t('zii', '{file} is too small, minimum file size is {minSizeLimit}.'), 'emptyError:' => Yii::t('zii', '{file} is empty, please select files again without it.'), 'noFilesError' => Yii::t('zii', 'No files to upload.'), 'onLeave' => Yii::t('zii', 'The files are being uploaded, if you leave now the upload will be cancelled.')));
 }
Ejemplo n.º 7
0
 /**
  * Helper method to display different input types for the different complain bootstrap forms wrapped with their
  * labels, help and error messages. This method is a replacement of the old 'typeRow' methods from Yii-Bootstrap
  * extension. Example:
  * <pre>
  *     $form->row(WhHtml::INPUT_TEXT, $model, 'attribute', array('style'=>'width:125px'));
  *    $form->row(WhHtml::INPUT_DROPDOWN, $model, 'attribute', array('a'=>'A','b'=>'B'), array());
  * </pre>
  * @param $type
  * @param $model
  * @param $attribute
  * @param $data
  * @param array $htmlOptions
  * @return string
  * @throws CException
  */
 public function row($type, $model, $attribute, $data = array(), $htmlOptions = array())
 {
     if (!in_array($type, WhHtml::validInputs())) {
         throw new CException(Yii::t('tb', 'Unrecognized input type'));
     }
     $labelOptions = WhHtml::popOption('labelOptions', $htmlOptions, array());
     $errorOptions = WhHtml::popOption('errorOptions', $htmlOptions, array());
     $containerOptions = WhHtml::popOption('containerOptions', $htmlOptions, array());
     $labelOptions = WhHtml::defaultOption('formType', $this->type, $labelOptions);
     ob_start();
     // make sure it holds the class control-label
     if ($this->type === WhHtml::FORM_HORIZONTAL) {
         echo CHtml::openTag('div', WhHtml::addClassName('control-group', $containerOptions));
     }
     // form's inline do not render labels and radio|checkbox input types render label's differently
     if ($this->type !== WhHtml::FORM_INLINE && !preg_match('/radio|checkbox/i', $type) && WhHtml::popOption('label', $htmlOptions, true)) {
         echo CHtml::activeLabel($model, $attribute, $labelOptions);
     } elseif (preg_match('/radio|checkbox/i', $type)) {
         $htmlOptions['labelOptions'] = $labelOptions;
     }
     if (WhHtml::popOption('block', $htmlOptions, false)) {
         $htmlOptions = WhHtml::addClassName('input-block-level', $htmlOptions);
     }
     $params = in_array($type, WhHtml::$dataInputs) ? array($model, $attribute, $data, $htmlOptions) : array($model, $attribute, $htmlOptions);
     $errorSpan = $this->error($model, $attribute, $errorOptions);
     echo $this->wrapControl(call_user_func_array('WhHtml::active' . ucfirst($type), $params), $errorSpan);
     /* since PHP 5.3 */
     if ($this->type == WhHtml::FORM_VERTICAL && WhHtml::popOption('error', $htmlOptions, true)) {
         echo $errorSpan;
     }
     if ($this->type == WhHtml::FORM_HORIZONTAL) {
         echo '</div>';
     }
     return ob_get_clean();
 }