input() публичный Метод

### Options See each field type method for more information. Any options that are part of $attributes or $options for the different **type** methods can be included in $options for input(). Additionally, any unknown keys that are not in the list below, or part of the selected type's options will be treated as a regular HTML attribute for the generated input. - type - Force the type of widget you want. e.g. type => 'select' - label - Either a string label, or an array of options for the label. See FormHelper::label(). - options - For widgets that take options e.g. radio, select. - error - Control the error message that is produced. Set to false to disable any kind of error reporting (field error and error messages). - empty - String or boolean to enable empty select box options. - nestedInput - Used with checkbox and radio inputs. Set to false to render inputs outside of label elements. Can be set to true on any input to force the input inside the label. If you enable this option for radio buttons you will also need to modify the default radioWrapper template. - templates - The templates you want to use for this input. Any templates will be merged on top of the already loaded templates. This option can either be a filename in /config that contains the templates you want to load, or an array of templates to use.
public input ( string $fieldName, array $options = [] ) : string
$fieldName string This should be "modelname.fieldname"
$options array Each type of input takes different options.
Результат string Completed form widget.
 public function input($fieldName, array $options = [])
 {
     $options += ['type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => []];
     $options = $this->_parseOptions($fieldName, $options);
     $options += ['id' => $this->_domId($fieldName)];
     $finalClasses = 'form-control';
     switch ($options['type']) {
         case 'checkbox':
             $finalClasses = '';
             $options['templates']['checkboxWrapper'] = '<div class="checkbox"><label>{{input}}{{label}}</label></div>';
             $options['templates']['label'] = '{{text}}';
             break;
         case 'radio':
             $options['templates']['radioWrapper'] = '<div class="radio"><label>{{input}}{{label}}</label></div>';
             $options['templates']['label'] = '{{text}}';
             break;
         case 'file':
             $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
             $options['templates']['label'] = isset($options['templates']['label']) ? $options['templates']['label'] : '<label>{{input}}{{text}}</label>';
             break;
         case 'password':
             $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
             $options['templates']['label'] = isset($options['templates']['label']) ? $options['templates']['label'] : '<label>{{input}}{{text}}</label>';
             break;
         default:
     }
     return parent::input($fieldName, $this->_injectStyles($options, $finalClasses));
 }
Пример #2
0
 /**
  * @return void
  */
 public function testFormInput()
 {
     $Form = new FormHelper(new View());
     $entity = $this->Table->newEntity();
     $Form->create($entity);
     $x = $Form->input('year_of_birth', ['type' => 'year']);
     $this->assertContains('<select name="year_of_birth[year]" type="year"', $x);
     // <div class="input number"><label for="year-of-birth">Year Of Birth</label><input type="number" name="year_of_birth" id="year-of-birth"/></div>
 }
Пример #3
0
 public function input($fieldName, array $options = array())
 {
     $defaultOptions = ['label' => false, 'div' => false, 'class' => 'form-control'];
     if ($this->useDefaults()) {
         return parent::input($fieldName, (array) array_merge($defaultOptions, $options));
     } else {
         return parent::input($fieldName, $options);
     }
 }
Пример #4
0
 public function input($fieldName, array $options = [])
 {
     if (!isset($options['type']) && !isset($options['options'])) {
         $modelKey = $this->model();
         if (preg_match('/^enum\\((.+)\\)$/ui', $this->fieldset[$modelKey]['fields'][$fieldName]['type'], $m)) {
             $match = trim($m[1]);
             $qOpen = substr($match, 0, 1);
             $qClose = substr($match, -1);
             $delimiter = $qOpen . ',' . $qClose;
             preg_match('/^' . $qOpen . '(.+)' . $qClose . '$/u', $match, $m);
             $_options = explode($delimiter, $m[1]);
             $options['type'] = 'select';
             $options['options'] = array_combine($_options, $_options);
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #5
0
 public function input($fieldName, array $options = [])
 {
     $options += ['type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => []];
     $options = $this->_parseOptions($fieldName, $options);
     $options += ['id' => $this->_domId($fieldName)];
     switch ($options['type']) {
         case 'checkbox':
             $options['templates']['checkboxWrapper'] = '<div class="checkbox"><label>{{input}}{{label}}</label></div>';
             $options['templates']['label'] = '{{text}}';
             break;
         case 'radio':
             $options['templates']['radioWrapper'] = '<div class="radio"><label>{{input}}{{label}}</label></div>';
             $options['templates']['label'] = '{{text}}';
             break;
         default:
     }
     return parent::input($fieldName, $this->_injectStyles($options, 'form-control'));
 }
Пример #6
0
 /**
  * {@inheritDoc}
  *
  * Allows to render Field (EAV virtual columns) in edit mode; it triggers the
  * event `Field.<handler>.Entity.edit`, it will try to append an `*` symbol to
  * input label if Field has been marked as "required".
  */
 public function input($fieldName, array $options = [])
 {
     if ($fieldName instanceof \Field\Model\Entity\Field) {
         if (!$this->_isRendering) {
             $this->_isRendering = true;
             $result = $fieldName->edit($this->_View);
             $this->_isRendering = false;
             return $result;
         } else {
             $options += ['value' => $fieldName->value, 'label' => $fieldName->label];
             if ($fieldName->metadata->required) {
                 $options['label'] .= ' *';
                 $options['required'] = 'required';
             }
             $fieldName = $fieldName->get('name');
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #7
0
 public function input($fieldName, array $options = [])
 {
     $context = $this->_getContext();
     $explodedFieldName = explode('.', $fieldName);
     if (!method_exists($context, 'entity')) {
         return parent::input($fieldName, $options);
     }
     $errors = $context->entity()->errors($explodedFieldName[0]);
     if (is_array($errors) && !empty($errors) && empty($this->error($fieldName))) {
         if (isset($errors[$explodedFieldName[1]][$explodedFieldName[2]])) {
             $error = array_values($errors[$explodedFieldName[1]][$explodedFieldName[2]])[0];
             $options['templates']['inputContainer'] = '<div class="input {{type}} required error">{{content}} <div class="error-message">' . $error . '</div></div>';
         }
     }
     if (isset($options['type']) && $options['type'] === 'translations') {
         unset($options['type']);
         $I18ns = TableRegistry::get('I18ns');
         $langs = $I18ns->find('list', ['keyField' => 'id', 'valueField' => 'locale', 'groupField' => 'is_required'])->toArray();
         $output = null;
         $fieldNames = [1 => 'translations', 0 => '_translations'];
         // ['required', 'not_required']
         foreach ($fieldNames as $key => $name) {
             if (array_key_exists($key, $langs)) {
                 foreach ($langs[$key] as $lang) {
                     $myOptions = $options;
                     if (!array_key_exists('required', $options)) {
                         $myOptions['required'] = $key === 1 ? true : false;
                     }
                     if (isset($context->entity()->_translations[$lang]->{$fieldName})) {
                         $myOptions['value'] = $context->entity()->_translations[$lang]->{$fieldName};
                     }
                     $myOptions['label'] = $lang . ' ' . $fieldName;
                     // Fix label
                     $output .= $this->input($name . '.' . $lang . '.' . $fieldName, $myOptions);
                 }
             }
         }
         return $output;
     }
     return parent::input($fieldName, $options);
 }
Пример #8
0
 /**
  * Generates an input element complete with label and wrapper div
  * @param string $fieldName Field name, should be "Modelname.fieldname"
  * @param array $options HTML attributes and options
  * @return string
  * @uses MeTools\View\Helper\HtmlHelper::para()
  * @uses $inline
  */
 public function input($fieldName, array $options = [])
 {
     //Resets templates
     $this->resetTemplates();
     //If the field name contains the word "password", then the field type
     //  is `password`
     if (preg_match('/password/', $fieldName)) {
         $options = $this->optionsDefaults(['type' => 'password'], $options);
     }
     //Gets the input type
     if (empty($options['type'])) {
         $type = self::_inputType($fieldName, $options);
     } else {
         $type = $options['type'];
     }
     // Adds the `form-control` class, except for checkboxes and file inputs
     if (!in_array($type, ['checkbox', 'file'])) {
         $options = $this->optionsValues(['class' => 'form-control'], $options);
     }
     if ($type === 'select' && empty($options['default']) && empty($options['value'])) {
         $options = $this->optionsDefaults(['empty' => true], $options);
     }
     //Help blocks
     //See http://getbootstrap.com/css/#forms-help-text
     if (!empty($options['help'])) {
         $options['templateVars']['help'] = implode(null, array_map(function ($tip) {
             return $this->Html->para('help-block', trim($tip));
         }, (array) $options['help']));
         unset($options['help']);
     }
     if (!empty($options['button'])) {
         //Fixes templates
         $this->templates(['formGroup' => '{{label}}<div class="input-group">{{input}}{{button}}</div>']);
         $options['templateVars']['button'] = $this->Html->span($options['button'], ['class' => 'input-group-btn']);
         unset($options['button']);
     }
     //If is an inline form
     if ($this->inline) {
         //By default, no help blocks or error messages
         $this->templates(['inputContainer' => '<div class="input form-group {{type}}{{required}}">{{content}}</div>', 'inputContainerError' => '<div class="input form-group {{type}}{{required}} has-error">{{content}}</div>']);
         //If it is not a checkbox
         if ($type !== "checkbox") {
             if (empty($options['label'])) {
                 $options['label'] = [];
             } elseif (is_string($options['label'])) {
                 $options['label'] = ['text' => $options['label']];
             }
             $options['label'] = $this->optionsValues(['class' => 'sr-only'], $options['label']);
         }
     }
     return parent::input($fieldName, $options);
 }
 /**
  *
  * Create & return an input block (Twitter Boostrap Like).
  *
  * New options:
  * 	- prepend:
  * 		-> string: Add <span class="add-on"> before the input
  * 		-> array: Add elements in array before inputs
  * 	- append: Same as prepend except it add elements after input
  *
  **/
 public function input($fieldName, array $options = array())
 {
     $options = $this->_parseOptions($fieldName, $options);
     $prepend = $this->_extractOption('prepend', $options, false);
     unset($options['prepend']);
     $append = $this->_extractOption('append', $options, false);
     unset($options['append']);
     if ($prepend || $append) {
         $prepend = $this->prepend(null, $prepend);
         $append = $this->append(null, $append);
     }
     $help = $this->_extractOption('help', $options, '');
     unset($options['help']);
     if ($help) {
         $append .= '<p class="help-block">' . $help . '</p>';
     }
     $inline = $this->_extractOption('inline', $options, '');
     unset($options['inline']);
     if ($options['type'] === 'radio') {
         $options['templates'] = [];
         if ($inline) {
             $options['templates'] = ['label' => $this->templates('label'), 'radioWrapper' => '{{label}}', 'nestingLabel' => '{{hidden}}<label{{attrs}} class="radio-inline">{{input}}{{text}}</label>'];
         }
         if ($this->horizontal) {
             $options['templates']['radioContainer'] = '<div class="form-group">{{content}}</div>';
         }
         if (empty($options['templates'])) {
             unset($options['templates']);
         }
     }
     $options['_data'] = ['prepend' => $prepend, 'append' => $append];
     return parent::input($fieldName, $options);
 }
Пример #10
0
 /**
  * Generates a form input element complete with label and wrapper div.
  *
  * Adds extra option besides the ones supported by parent class method:
  * - `append` - Append addon to input.
  * - `prepend` - Prepend addon to input.
  * - `inline` - Boolean for generating inline checkbox/radio.
  * - `help` - Help text of include in the input container.
  *
  * @param string $fieldName This should be "Modelname.fieldname".
  * @param array $options Each type of input takes different options.
  * @return string Completed form widget.
  */
 public function input($fieldName, array $options = [])
 {
     $options += ['prepend' => null, 'append' => null, 'inline' => null, 'type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'help' => null, 'templates' => [], 'templateVars' => []];
     $options = $this->_parseOptions($fieldName, $options);
     $newTemplates = $options['templates'];
     if ($newTemplates) {
         $this->templater()->push();
         $templateMethod = is_string($options['templates']) ? 'load' : 'add';
         $this->templater()->{$templateMethod}($options['templates']);
         $options['templates'] = [];
     }
     switch ($options['type']) {
         case 'checkbox':
             if (!isset($options['inline'])) {
                 $options['inline'] = $this->checkClasses($options['type'] . '-inline', (array) $options['label']);
             }
             if ($options['inline']) {
                 $options['label'] = $this->injectClasses($options['type'] . '-inline', (array) $options['label']);
                 if (!isset($newTemplates['checkboxContainer'])) {
                     $options['templates']['checkboxContainer'] = '{{content}}';
                 }
             }
             unset($options['inline']);
             break;
         case 'radio':
             if ($options['inline'] && $this->_align !== 'horizontal') {
                 $options['templates']['formGroup'] = $this->templater()->get('radioInlineFormGroup');
             }
             if (!$options['inline']) {
                 $options['templates']['nestingLabel'] = $this->templater()->get('radioNestingLabel');
             }
             break;
         case 'select':
             if (isset($options['multiple']) && $options['multiple'] === 'checkbox') {
                 $options['templates']['checkboxWrapper'] = $this->templater()->get('multipleCheckboxWrapper');
                 $options['type'] = 'multicheckbox';
             }
             break;
         case 'multiselect':
             break;
         case 'textarea':
         default:
             if ($options['label'] !== false && strpos($this->templates('label'), 'class=') === false) {
                 $options['label'] = $this->injectClasses('control-label', (array) $options['label']);
             }
     }
     if ($options['help']) {
         $options['help'] = $this->templater()->format('help', ['content' => $options['help']]);
     }
     $result = parent::input($fieldName, $options);
     if ($newTemplates) {
         $this->templater()->pop();
     }
     return $result;
 }
Пример #11
0
 /**
  * Test construct() with the templates option.
  *
  * @return void
  */
 public function testConstructTemplatesFile()
 {
     $helper = new FormHelper($this->View, ['templates' => 'htmlhelper_tags']);
     $result = $helper->input('name');
     $this->assertContains('<input', $result);
 }
Пример #12
0
 /**
  * Generates a form input element complete with label and wrapper div.
  *
  * @param string $fieldName
  * @param array $options
  * @return string
  */
 public function input($fieldName, array $options = [])
 {
     $options = $this->_getToolTipAttr($options, 'tooltip-input');
     $options = $this->_getBtnClass($options);
     $options['fieldName'] = $fieldName;
     $options = $this->Wysiwyg->input($fieldName, $options);
     return parent::input($fieldName, $options);
 }
    public function input($fieldName, array $options = [])
    {
        $options += ['type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => []];
        $options = $this->_parseOptions($fieldName, $options);
        $options += ['id' => $this->_domId($fieldName)];
        $finalClasses = 'form-control';
        switch ($options['type']) {
            case 'checkbox':
                $finalClasses = '';
                $options['templates']['checkboxWrapper'] = '<div class="checkbox"><label>{{input}}{{label}}</label></div>';
                $options['templates']['label'] = '{{text}}';
                break;
            case 'radio':
                $options['templates']['radioWrapper'] = '<div class="radio"><label>{{input}}{{label}}</label></div>';
                $options['templates']['label'] = '{{text}}';
                break;
            case 'file':
                $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
                $options['templates']['label'] = '<label>{{input}}{{text}}</label>';
                if (!empty($options['value'])) {
                    $label = $options['label'] ? $options['label'] : Inflector::humanize($fieldName);
                    $function_name = "enable_{$fieldName}()";
                    $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">
                      {{content}}
                      <div>
                        <small>
                            <label>
                            <input type="checkbox" onclick="' . $function_name . '" />
                            ' . __("Click here to change the file.") . '
                            </label>
                        </small>

                        <script type="text/javascript">
                            function ' . $function_name . ' {
                                if (document.getElementById("' . $fieldName . '").disabled) {
                                    document.getElementById("' . $fieldName . '").disabled = false;
                                } else {
                                    document.getElementById("' . $fieldName . '").disabled = true;
                                }
                            }
                        </script>
                      </div>
                    </div>';
                    $options['disabled'] = true;
                }
                break;
            case 'password':
                $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
                $options['templates']['label'] = '<label>{{input}}{{text}}</label>';
                if (!empty($options['value'])) {
                    $label = $options['label'] ? $options['label'] : Inflector::humanize($fieldName);
                    $function_name = "enable_{$fieldName}()";
                    $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">
                      {{content}}
                      <div>
                        <small>
                            <label>
                            <input type="checkbox" onclick="' . $function_name . '" />
                            ' . __("Click here to change the file.") . '
                            </label>
                        </small>

                        <script type="text/javascript">
                            function ' . $function_name . ' {
                                if (document.getElementById("' . $fieldName . '").disabled) {
                                    document.getElementById("' . $fieldName . '").disabled = false;
                                } else {
                                    document.getElementById("' . $fieldName . '").disabled = true;
                                }
                            }
                        </script>
                      </div>
                    </div>';
                    $options['disabled'] = true;
                    $options['value'] = '';
                }
                break;
            default:
        }
        return parent::input($fieldName, $this->_injectStyles($options, $finalClasses));
    }
Пример #14
0
 /**
  * Generates a form input element complete with label and wrapper div.
  *
  * Adds extra option besides the ones supported by parent class method:
  * - `help` - Help text of include in the input container.
  *
  * @param string $fieldName This should be "Modelname.fieldname".
  * @param array $options Each type of input takes different options.
  * @return string Completed form widget.
  */
 public function input($fieldName, array $options = [])
 {
     $options += ['prepend' => null, 'append' => null, 'type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'help' => null, 'templates' => []];
     $options = $this->_parseOptions($fieldName, $options);
     $reset = $this->templates();
     switch ($options['type']) {
         case 'checkbox':
         case 'radio':
             if (!isset($options['inline'])) {
                 $options['inline'] = $this->checkClasses($options['type'] . '-inline', (array) $options['label']);
             }
             if ($options['inline']) {
                 $options['label'] = $this->injectClasses($options['type'] . '-inline', (array) $options['label']);
             }
             break;
         case 'select':
             if (isset($options['multiple']) && $options['multiple'] === 'checkbox') {
                 $this->templates(['checkboxWrapper' => '<div class="checkbox">{{label}}</div>']);
                 $options['type'] = 'multicheckbox';
             }
             break;
         case 'multiselect':
         case 'textarea':
             break;
         default:
             if ($options['label'] !== false && strpos($this->templates('label'), 'class=') === false) {
                 $options['label'] = $this->injectClasses('control-label', (array) $options['label']);
             }
     }
     if (!in_array($options['type'], ['checkbox', 'radio', 'hidden', 'staticControl'])) {
         $options = $this->injectClasses('form-control', $options);
     }
     if ($options['help']) {
         $options['help'] = $this->templater()->format('help', ['content' => $options['help']]);
     }
     $result = parent::input($fieldName, $options);
     $this->templates($reset);
     return $result;
 }
Пример #15
0
 /** 
  * 
  * Create & return an input block (Twitter Boostrap Like).
  * 
  * New options:
  * 	- prepend: 
  * 		-> string: Add <span class="add-on"> before the input
  * 		-> array: Add elements in array before inputs
  * 	- append: Same as prepend except it add elements after input
  *        
  **/
 public function input($fieldName, array $options = array())
 {
     $prepend = $this->_extractOption('prepend', $options, '');
     unset($options['prepend']);
     $append = $this->_extractOption('append', $options, '');
     unset($options['append']);
     $inline = $this->_extractOption('inline', $options, '');
     unset($options['inline']);
     $oldTemplates = ['input' => $this->templates('input'), 'label' => $this->templates('label'), 'radioWrapper' => $this->templates('radioWrapper'), 'nestingLabel' => $this->templates('nestingLabel'), 'radioContainer' => $this->templates('radioContainer')];
     if ($prepend || $append) {
         $before = '';
         $after = '';
         if ($prepend) {
             if (is_string($prepend)) {
                 $before = '<span class="input-group-' . ($this->_matchButton($prepend) ? 'btn' : 'addon') . '">' . $prepend . '</span>';
             } else {
                 $before = '<span class="input-group-btn">' . implode('', $prepend) . '</span>';
             }
         }
         if ($append) {
             if (is_string($append)) {
                 $after = '<span class="input-group-' . ($this->_matchButton($append) ? 'btn' : 'addon') . '">' . $append . '</span>';
             } else {
                 $after = '<span class="input-group-btn">' . implode('', $append) . '</span>';
             }
         }
         $this->templates(['input' => '<div class="input-group">' . $before . '<input class="form-control" {{attrs}} type="{{type}}" name="{{name}}" id="{{name}}" />' . $after . '</div>']);
     }
     $options = $this->_parseOptions($fieldName, $options);
     if ($inline) {
         if ($options['type'] === 'radio') {
             $this->templates(['label' => $oldTemplates['label'] . '<div></div>', 'radioWrapper' => '{{label}}', 'nestingLabel' => '{{hidden}}<label{{attrs}} class="radio-inline">{{input}}{{text}}</label>']);
         }
     }
     if ($this->horizontal && $options['type'] === 'radio') {
         $this->templates(['radioContainer' => '<div class="form-group">{{content}}</div>']);
     }
     $res = parent::input($fieldName, $options);
     $this->templates($oldTemplates);
     return $res;
 }
Пример #16
0
 /**
  * Generates a form input element complete with label and wrapper div.
  *
  * Adds extra option besides the ones supported by parent class method:
  * - `help` - Help text of include in the input container.
  *
  * @param string $fieldName This should be "Modelname.fieldname".
  * @param array $options Each type of input takes different options.
  * @return string Completed form widget.
  */
 public function input($fieldName, array $options = [])
 {
     $options += ['prepend' => null, 'append' => null, 'type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'help' => null, 'templates' => []];
     $options = $this->_parseOptions($fieldName, $options);
     $reset = $this->templates();
     switch ($options['type']) {
         case 'checkbox':
             if (!isset($options['inline'])) {
                 $options['inline'] = $this->checkClasses($options['type'] . '-inline', (array) $options['label']);
             }
             if ($options['inline']) {
                 $options['label'] = $this->injectClasses($options['type'] . '-inline', (array) $options['label']);
             }
             break;
         case 'radio':
             $isInline = isset($options['inline']) && $options['inline'] === true;
             $templates = [];
             if ($isInline && $this->_align !== 'horizontal') {
                 $templates['formGroup'] = $this->templater()->get('radioInlineFormGroup');
             }
             if (!$isInline) {
                 $templates['nestingLabel'] = $this->templater()->get('radioNestingLabel');
             }
             $this->templater()->add($templates);
             break;
         case 'select':
             if (isset($options['multiple']) && $options['multiple'] === 'checkbox') {
                 $this->templater()->add(['checkboxWrapper' => $this->templater()->get('multipleCheckboxWrapper')]);
                 $options['type'] = 'multicheckbox';
             }
             break;
         case 'multiselect':
             break;
         case 'textarea':
         default:
             if ($options['label'] !== false && strpos($this->templates('label'), 'class=') === false) {
                 $options['label'] = $this->injectClasses('control-label', (array) $options['label']);
             }
     }
     if (!in_array($options['type'], ['checkbox', 'radio', 'hidden', 'staticControl'])) {
         $options = $this->injectClasses('form-control', $options);
     }
     if ($options['help']) {
         $options['help'] = $this->templater()->format('help', ['content' => $options['help']]);
     }
     $result = parent::input($fieldName, $options);
     $this->templates($reset);
     return $result;
 }
Пример #17
0
 /**
  * Reload core input.
  *
  * @param string $fieldName
  * @param array $options
  * @return string
  */
 public function input($fieldName, array $options = [])
 {
     //  Set label tooltip.
     if (isset($options['label']['tooltip'])) {
         $_toolTipPos = 'top';
         if (isset($options['label']['tooltipPosition'])) {
             $_toolTipPos = $options['label']['tooltipPosition'];
             unset($options['label']['tooltipPosition']);
         }
         if (is_string($options['label']['tooltip']) && !isset($options['label']['title'])) {
             $options['label']['title'] = $options['label']['tooltip'];
         }
         $toolTipOptions = ['label' => ['data-toggle' => 'tooltip', 'data-placement' => $_toolTipPos, 'title' => !isset($options['label']['title']) ? (string) $options['label']['tooltip'] : $options['label']['title']]];
         unset($options['label']['tooltip']);
         $options = Hash::merge($toolTipOptions, $options);
         if (!isset($options['label']['text'])) {
             $options['label']['text'] = $options['label']['title'];
         }
     }
     return parent::input($fieldName, $options);
 }
 /**
  * Override
  *
  * @param string $fieldName field name
  * @param array $options An array of HTML attributes.
  * @return string
  */
 public function input($fieldName, array $options = [])
 {
     $input = parent::input($fieldName, $options);
     return $input;
 }
Пример #19
0
 /**
  * Generates a form input element complete with label and wrapper div.
  *
  * @param string $fieldName This should be "Modelname.fieldname".
  * @param array $options Each type of input takes different options.
  * @return string Completed form widget.
  */
 public function input($fieldName, array $options = [])
 {
     $options += ['prepend' => null, 'append' => null, 'type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => []];
     $options = $this->_parseOptions($fieldName, $options);
     $reset = $this->templates();
     switch ($options['type']) {
         case 'checkbox':
         case 'radio':
             $this->templates(['label' => '{{text}}']);
             if (!isset($options['inline'])) {
                 $options['inline'] = $this->checkClasses('checkbox-inline', (array) $options['label']) || $this->checkClasses('radio-inline', (array) $options['label']);
             }
             if ($options['inline']) {
                 $options['label'] = $this->injectClasses('checkbox-inline', (array) $options['label']);
                 $this->templates(['inputContainer' => '{{content}}']);
             }
             unset($options['inline']);
             break;
         case 'select':
             if (isset($options['multiple']) && $options['multiple'] === 'checkbox') {
                 $this->templates(['checkboxWrapper' => '<div class="checkbox">{{label}}</div>']);
                 $options['type'] = 'multicheckbox';
             }
             break;
         case 'multiselect':
         case 'textarea':
             break;
         default:
             if ($options['label'] !== false && strpos($this->templates('label'), 'class=') === false) {
                 $options['label'] = $this->injectClasses('control-label', (array) $options['label']);
             }
             $prepend = $options['prepend'];
             $append = $options['append'];
             if (empty($prepend) && empty($append)) {
                 break;
             }
             $input = $reset['input'];
             if ($prepend) {
                 if (is_string($prepend)) {
                     $class = 'input-group-' . ($this->_isButton($prepend) ? 'btn' : 'addon');
                     $input = $this->Html->tag('span', $prepend, compact('class')) . $input;
                 } else {
                     $class = 'input-group-btn';
                     $input = $this->Html->tag('span', implode('', $prepend), compact('class')) . $input;
                 }
             }
             if ($append) {
                 if (is_string($append)) {
                     $class = 'input-group-' . ($this->_isButton($append) ? 'btn' : 'addon');
                     $input .= $this->Html->tag('span', $append, compact('class'));
                 } else {
                     $class = 'input-group-btn';
                     $input .= $this->Html->tag('span', implode('', $append), compact('class'));
                 }
             }
             $input = $this->Html->div('input-group', $input, ['escape' => false]);
             $this->templates(compact('input'));
     }
     if (!in_array($options['type'], ['checkbox', 'radio'])) {
         $options = $this->injectClasses('form-control', $options);
     }
     unset($options['prepend'], $options['append']);
     $result = parent::input($fieldName, $options);
     $this->templates($reset);
     return $result;
 }
 /** 
  * 
  * Create & return an input block (Twitter Boostrap Like).
  * 
  * New options:
  * 	- prepend: 
  * 		-> string: Add <span class="add-on"> before the input
  * 		-> array: Add elements in array before inputs
  * 	- append: Same as prepend except it add elements after input
  *        
  **/
 public function input($fieldName, array $options = array())
 {
     $prepend = $this->_extractOption('prepend', $options, '');
     unset($options['prepend']);
     $append = $this->_extractOption('append', $options, '');
     unset($options['append']);
     $oldTemplate = $this->templates('input');
     if ($prepend || $append) {
         $before = '';
         $after = '';
         if ($prepend) {
             if (is_string($prepend)) {
                 $before = '<span class="input-group-' . ($this->_matchButton($prepend) ? 'btn' : 'addon') . '">' . $prepend . '</span>';
             } else {
                 $before = '<span class="input-group-btn">' . implode('', $prepend) . '</span>';
             }
         }
         if ($append) {
             if (is_string($append)) {
                 $after = '<span class="input-group-' . ($this->_matchButton($append) ? 'btn' : 'addon') . '">' . $append . '</span>';
             } else {
                 $after = '<span class="input-group-btn">' . implode('', $append) . '</span>';
             }
         }
         $this->templates(['input' => '<div class="input-group">' . $before . '<input class="form-control" {{attrs}} type="{{type}}" name="{{name}}" id="{{name}}" />' . $after . '</div>']);
     }
     $res = parent::input($fieldName, $options);
     $this->templates(['input' => $oldTemplate]);
     return $res;
 }