Builds checkbox / radio controls

@return string html
515116
protected function buildCheckboxRadioGroup()
    {
        $optHtml = '';
        $props = &$this->props;
        $optTemplate = '<div {{attribsPair}}>'
            .'<label {{attribsLabel}}>'
                .'{{input}}'
                .'{{label}}'
            .'</label>'
            .'</div>'."\n";
        $values = $props['attribs']['type'] == 'radio'
            ? (array) $props['attribs']['value']
            : $props['values'];
        $isMultiple = \count($props['options']) > 1;
        foreach ($props['options'] as $i => $optProps) {
            // unset($optProps['attribs']['tagname']);
            $optProps = $this->mergeProps(array(
                array(
                    'attribs' => $props['attribs'], // name, type, & other "global" attributes
                ),
                array(
                    'attribs' => array(
                        'checked' => \in_array($optProps['attribs']['value'], $values),
                    ),
                    'attribsLabel' => array(),
                    'attribsPair' => array( 'class' => $props['attribs']['type'] ),
                ),
                $optProps,
                array(
                    'attribs' => array(
                        'id' => $props['attribs']['id']
                            ? $props['attribs']['id'].($isMultiple ? '_'.($i+1) : '')
                            : null,
                    ),
                ),
            ));
            if (!empty($optProps['attribs']['disabled'])) {
                $this->classAdd($optProps['attribsPair'], 'disabled');
            }
            $attribStrings = $this->buildAttribStrings($optProps);
            $optProps['input'] = '<input '.$attribStrings['attribs'].' />';
            $props['options'][$i] = $optProps;
            $optProps = \array_merge($optProps, $attribStrings);
            $optProps['label'] = \htmlspecialchars($optProps['label']);
            $optHtml .= Str::quickTemp($optTemplate, $optProps);
        }
        return $optHtml;
    }
1176463
public function buildCode()
	{
		$select		= UI_HTML_Elements::Select( $this->name, $this->options, $this->class );
		return $select;
	}
1021029
public function controlDataForJs()
    {
        return [
            // Text Control
            'size'               => $this->size(),
            'min_length'         => $this->minLength(),
            'max_length'         => $this->maxLength(),

            // Base Control
            'input_name'         => $this->inputName(),
            'input_val'          => $this->inputVal(),

            // Base Property
            'readOnly'           => $this->readOnly(),
            'required'           => $this->required(),
            'l10n'               => $this->property()->l10n(),
            'multiple'           => $this->multiple(),
            'multiple_separator' => $this->property()->multipleSeparator(),
            'multiple_options'   => $this->property()->multipleOptions(),
        ];
    }
753482
public function htmlConfigForm() {	
		$html = '
			<div class="form-group">
    			<label class="control-label col-sm-3"> '.
    				I18N::translate('Enable healthcheck emails for') .
    			'</label>
    			<div class="col-sm-9">';

		foreach(Tree::getAll() as $tree){
			if(Auth::isManager($tree)){	
			    $html .= '<div class="form-group row">
			        <span class="col-sm-3 control-label">' .
			             $tree->getTitle() .
					'</span>
					 <div class="col-sm-2">';
				$html .= FunctionsEdit::editFieldYesNo('HEALTHCHECK_ENABLED_' . $tree->getTreeId(), $tree->getPreference('MAJ_AT_'.$this->getName().'_ENABLED', 1), 'class="radio-inline"');
				$html .= '</div></div>';
			}
		}
		
		$html .= '	<p class="small text-muted">'.
    					I18N::translate('Enable the health check emails for each of the selected trees.') .
    				'</p>
    			</div>
    		</div>';
			
		return $html;
	}
588814
public function radioButton(RadioButton $radioButton)
    {
        $label = new Tag('label');

        $tag = new Tag('input');
        $tag->setAttribute('type', 'checkbox');

        if ($radioButton->isChecked()) {
            $tag->setAttribute('checked', 'checked');
        }

        $tagHtml = $this->parseTag($tag, $radioButton);

        $label->setInnerHtml(
            $tagHtml . ' ' . ($radioButton->getLabel() ?: $radioButton->getTitle())
        );

        $div = new Tag('div');

        $cssClass = 'radio';
        if( $radioButton->isDisabled() ) {
            $cssClass .= ' disabled';
        }

        if ($radioButton->getForm()->isSubmitted()) {
            if (!$radioButton->isValid()) {
                $cssClass .= ' has-error has-feedback';
            } else {
                $cssClass .= ' has-success has-feedback';
            }
        }

        $div->setAttribute('class', $cssClass);
        $div->setInnerHtml($label->render());
        $html = $div->render();

        // if it's an horizontal form, then add some more classes
        if ($this->mode == self::MODE_HORIZONTAL) {
            $innerDiv = new Tag('div');
            $innerDiv->setAttribute('class', 'col-sm-offset-2 col-sm-10');
            $innerDiv->setInnerHtml($html);

            $outerDiv = new Tag('div');
            $outerDiv->setAttribute('class', 'form-group');
            $outerDiv->setInnerHtml($innerDiv->render());

            $html = $outerDiv->render();
        }

        return $html;
    }
1110776
public function createMethodElement() {
        $multiOptions = $this->util->getTranslated()->getBulkMailProcessOptions();
        $options      = array(
            'label'        => $this->translate->_('Method'),
            'multiOptions' => $multiOptions,
            'required'     => true,
        );

        return $this->_form->createElement('radio', 'multi_method', $options);
    }
749538
private function build() {

        $this -> fill();

        $html = '<input type="'. $this -> type .'"';
        
        foreach($this -> attributes as $attribute => $value) {
            $html .= ' ' . $attribute . '="'. Escape :: attr($value) .'"';
        }

        $html .= '>';

        return $html;
    }
1000120
private function build() {

    	if(null === $this -> text) {

    		$html = '<input type="'. $this -> type .'"';
    		
    		foreach($this -> attributes as $attribute => $value) {
    		    $html .= ' ' . $attribute . '="'. Escape :: attr($value) .'"';
    		}

    		$html .= '>';

    		return $html;
    	}

        $this -> fill();
        
        $html = '<button';
        
        foreach($this -> attributes as $attribute => $value) {
            $html .= ' ' . $attribute . '="'. Escape :: attr($value) .'"';
        }

        $html .= '>' . Escape :: html($this -> text) . '</button>';

        return $html;
        
    }
490384
static public function checkbox_group($name, $value=null, $settings=[], $is_radio=false)
    {
        $form_type  = $is_radio ? 'radio' : 'checkbox';
        
        if (!$is_radio && strpos($name, '[]') === false) {
            $name .= '[]';
        }
        $settings = static::formatSettings($settings);
        
        $form_id = isset($settings['id']) ? $settings['id'] : static::formatId($name);
        unset($settings['id']);
        
        $classes = isset($settings['class']) ? explode(' ', $settings['class']) : [];
        $css_inline = (isset($settings['form-inline']) && $settings['form-inline'])|| in_array('inline', $classes) || in_array('list-inline', $classes) ? : false;
        $classes = array_diff($classes, ['inline', 'list-inline']);
        array_push($classes, 'ace');
        $settings['class'] = implode(' ', $classes);
        
        $str = sprintf('<ul class="control-group list-unstyled%s">', $css_inline ? ' list-inline' : '') . PHP_EOL;
        
        if ($settings['data_source']) {
            $fields     = $settings['fields'];
            foreach ($settings['data_source'] as $k => $v) {
                if (is_scalar($v)) {
                    $_value = $k;
                    $_title = $v;
                } else {
                    $_value = isset($v[$fields[0]]) ? $v[$fields[0]] : 0;
                    $_title = isset($v[$fields[1]]) ? $v[$fields[1]] : (isset($v['name']) ? $v['name'] : '无法解析名称');
                }
                // checked, if set value-bit(value like 1,2,4) then use bit type
                if (isset($settings['value-bit']) && $settings['value-bit']) {
                    $checked = (intval($value) & $_value) ? ' checked="checked"' : '';
                } else {
                    $checked_values = isset($settings['checked']) ? $settings['checked'] : $value;
                    $checked_values = is_null($checked_values) || $checked_values === '' ? [] : (array) $checked_values;
                    $checked = in_array($_value, $checked_values) ? ' checked="checked"' : '';
                }
                
                $str .= sprintf('<li class="%s">', $css_inline ? '' : 'list-group-item') . PHP_EOL;
                if (isset($v['depth'])) $str .= str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $v['depth']);
                $str .= '   <input type="'.$form_type.'" name="'. $name .'" value="'.$_value.'" class="' . $settings['class'] . '" data-group="'.$_title.'" '.$checked.' > ' . PHP_EOL;
                $str .= '   <span class="lbl"> '.$_title.' </span> ' . PHP_EOL;
                $str .= '</li>' . PHP_EOL;
            }
        } else {
            $str .= '<li>' . PHP_EOL;
            $str .= static::$form_type($name, $value, $settings);
            $str .= '</li>' . PHP_EOL;
        }
        
        $str .= '</ul>' . PHP_EOL;
        return $str;
    }
1128314
protected function buildControl($type, $name, $value, $attributes, $options, $htmlName, $hasErrors = false)
    {
        switch ($type) {
            case 'password':
            case 'file':
                return $this->form->$type($htmlName, $attributes);
            case 'select':
                return $this->form->$type(
                    $htmlName,
                    $this->addEmptyOption(
                        $name,
                        $this->getOptionsList($name, $options),
                        $attributes
                    ),
                    $value,
                    $attributes
                );
            case 'radios':
            case 'checkboxes':
                return $this->form->$type(
                    $htmlName,
                    $this->getOptionsList($name, $options),
                    $value,
                    $attributes,
                    $hasErrors
                );
            case 'checkbox':
                return $this->form->checkbox(
                    $htmlName,
                    $options ?: 1,
                    $value,
                    $attributes
                );
            default:
                return $this->form->$type($htmlName, $value, $attributes);
        }
    }
280151
public function buildForm()
    {

        $this
            ->add($this->model->getKeyName(), 'hidden')
            ->add('email', 'email',
                [
                    'label'      => trans('expendable::form.email'),
                    'validation' => 'required,custom[email]',
                ]);

        $id = $this->model->getKey();

        if (!empty($id))
        {
            $this->add('change_password', 'checkbox', [
                'default_value' => 1,
                'label'         => trans('expendable::form.change_password_help'),
                'checked'       => false,
                'noInEditView'  => true
            ]);
        }

        $this->add('password', 'password',
            [
                'label'        => trans('expendable::form.password'),
                'attr'         => ['id' => 'password'],
                'validation'   => 'required',
                'noInEditView' => true
            ])
            ->add('password_match', 'password',
                [
                    'label'        => trans('expendable::form.repeat_password'),
                    'validation'   => 'required,equals[password]',
                    'noInEditView' => true
                ])
            ->add('status', 'choice', [
                'choices'     => StaticLabel::status(),
                'empty_value' => '-',
                'validation'  => 'required',
                'label'       => trans('expendable::form.status')
            ])
            ->add('role_id', 'choice', [
                'choices'     => Role::getChoice(),
                'empty_value' => '-',
                'validation'  => 'required',
                'label'       => trans('expendable::form.role')
            ])
            ->addDefaultActions();
    }
492414
public function getHtmlElements() : string
    {
        $elementString = '';
        /*
         | Build a form and store as string
         */
        foreach ($this->elements[self::$formHolder[self::$formName]] as $key => $val) {
            $elementString .= $val;
        }

        return $elementString;
    }
203852
function toHtml() {
        global $CFG, $PAGE;

        $this->_generateId();
        $elementid = $this->getAttribute('id');
        $mainhtml = html_writer::tag('div', $this->items[$this->getValue()]->mainhtml,
                array('id' => $elementid . '_items_main', 'class' => 'formlistingmain'));

        // Add the main div containing the selected item (+ the caption: "More items").
        $html = html_writer::tag('div', $mainhtml .
                    html_writer::tag('div', $this->showall,
                        array('id' => $elementid . '_items_caption', 'class' => 'formlistingmore')),
                    array('id' => $elementid . '_items', 'class' => 'formlisting hide'));

        // Add collapsible region: all the items.
        $itemrows = '';
        $html .= html_writer::tag('div', $itemrows,
                array('id' => $elementid . '_items_all', 'class' => 'formlistingall'));

        // Add radio buttons for non javascript support.
        $radiobuttons = '';
        foreach ($this->items as $itemid => $item) {
            $radioparams = array('name' => $this->getName(), 'value' => $itemid,
                    'id' => 'id_'.$itemid, 'class' => 'formlistinginputradio', 'type' => 'radio');
            if ($itemid == $this->getValue()) {
                $radioparams['checked'] = 'checked';
            }
            $radiobuttons .= html_writer::tag('div', html_writer::tag('input',
                html_writer::tag('div', $item->rowhtml, array('class' => 'formlistingradiocontent')), $radioparams),
                array('class' => 'formlistingradio'));
        }

        // Container for the hidden hidden input which will contain the selected item.
        $html .= html_writer::tag('div', $radiobuttons,
                array('id' => 'formlistinginputcontainer_' . $elementid, 'class' => 'formlistinginputcontainer'));

        $module = array('name'=>'form_listing', 'fullpath'=>'/lib/form/yui/listing/listing.js',
            'requires'=>array('node', 'event', 'transition', 'escape'));

        $PAGE->requires->js_init_call('M.form_listing.init',
                 array(array(
                'elementid' => $elementid.'_items',
                'hideall' => $this->hideall,
                'showall' => $this->showall,
                'hiddeninputid' => $this->getAttribute('id'),
                'items' => $this->items,
                'inputname' => $elementid,
                'currentvalue' => $this->getValue())), true, $module);

        return $html;
    }
1269069
public function run() {
		
		echo CHtml::openTag('div', $this->htmlOptions);

		foreach ($this->buttons as $button) {
			if (isset($button['visible']) && $button['visible'] === false) {
				continue;
			}
			
			$validToggles = array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO);
			if (isset($this->toggle) && in_array($this->toggle, $validToggles)) {
				$this->buttonType = $this->toggle;
			}
			
			$justifiedNotLink = $this->justified && $this->buttonType !== TbButton::BUTTON_LINK;
			if($justifiedNotLink)
				echo '<div class="btn-group">';
			
			$this->controller->widget(
				'booster.widgets.TbButton',
				array(
					'buttonType' => isset($button['buttonType']) ? $button['buttonType'] : $this->buttonType,
					'context' => isset($button['context']) ? $button['context'] : $this->context,
					'size' => $this->size, // all buttons in a group cannot vary in size
					'icon' => isset($button['icon']) ? $button['icon'] : null,
					'label' => isset($button['label']) ? $button['label'] : null,
					'url' => isset($button['url']) ? $button['url'] : null,
					'active' => isset($button['active']) ? $button['active'] : false,
					'disabled' => isset($button['disabled']) ? $button['disabled'] : false,
					'items' => isset($button['items']) ? $button['items'] : array(),
					'ajaxOptions' => isset($button['ajaxOptions']) ? $button['ajaxOptions'] : array(),
					'htmlOptions' => isset($button['htmlOptions']) ? $button['htmlOptions'] : array(),
					'dropdownOptions' => isset($button['dropdownOptions']) ? $button['dropdownOptions'] : array(),
					'encodeLabel' => isset($button['encodeLabel']) ? $button['encodeLabel'] : $this->encodeLabel,
                    'tooltip' => isset($button['tooltip']) ? $button['tooltip'] : false,
                    'tooltipOptions' => isset($button['tooltipOptions']) ? $button['tooltipOptions'] : array(),
				)
			);
			
			if($justifiedNotLink)
				echo '</div>';
		}
		echo '</div>';
	}
1005271
public function controls()
    {
        $this->form();
        $form      = app('antares.form')->of("antares.ui-components: custom");
        $fieldsets = $form->grid->fieldsets();
        $controls  = [];
        foreach ($fieldsets as $fieldset) {
            foreach ($fieldset->controls as $control) {
                array_push($controls, $control->name);
            }
        }
        return $controls;
    }
708489
protected function createChildren()
    {
        $this->children = [];
        $this->determineChoiceField();

        $fieldType = $this->formHelper->getFieldType($this->choiceType);

        switch ($this->choiceType) {
            case 'radio':
            case 'checkbox':
                $this->buildCheckableChildren($fieldType);
                break;
            default:
                $this->buildSelect($fieldType);
                break;
        }
    }
902240
protected function checkBox(CheckBox $checkbox)
    {
        $tag = new Tag('input');
        $tag->setAttribute('type', 'checkbox');

        if (!$checkbox->getId() && $checkbox->getLabel()) {
            $checkbox->setId('field-' . uniqid('checkbox'));
        }

        if ($checkbox->isChecked()) {
            $tag->setAttribute('checked', 'checked');
        }

        $html = $this->parseTag($tag, $checkbox);

        if ($checkbox->getLabel()) {
            $label = new Tag('label', $checkbox->getLabel());
            $label->setAttribute('for', $checkbox->getId());
            $html .= $label->render();
        }

        return $html;
    }