Ejemplo n.º 1
0
 /**
  * Make function of current field type. Return compiled html response
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function make()
 {
     // get options from properties
     $options = $this->properties['options'];
     if (!Obj::isIterable($options)) {
         throw new SyntaxException('Radio field ' . self::nohtml($this->name) . ' have no iterable options');
     }
     unset($this->properties['options'], $this->properties['value']);
     // options is defined as key->value array?
     $optionsKey = $this->properties['optionsKey'] === true;
     unset($this->properties['optionsKey']);
     $build = null;
     // build output dom html
     foreach ($options as $idx => $value) {
         $property = $this->properties;
         if ($optionsKey === true) {
             // radio button as [value => text_description] - values is a key
             $property['value'] = $idx;
             if ($idx == $this->value) {
                 $property['checked'] = null;
                 // def boolean attribute html5
             }
         } else {
             // radio button only with [value] data
             $property['value'] = $value;
             if ($value == $this->value) {
                 $property['checked'] = null;
                 // def boolean attribute html5
             }
         }
         // get template and concat avg response
         $build .= App::$View->render('native/form/radio_list', ['tag' => self::buildSingleTag('input', $property), 'text' => $value]);
     }
     return $build;
 }
Ejemplo n.º 2
0
 /**
  * Build <input type="checkbox" checked {$properties} /> response
  * {@inheritDoc}
  * @see \Ffcms\Core\Helper\HTML\Form\iField::make()
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function make()
 {
     // check if options is defined
     $options = $this->properties['options'];
     if (!Obj::isIterable($options)) {
         throw new SyntaxException('Options for field ' . self::nohtml($this->name) . ' is not iterable');
     }
     unset($this->properties['options']);
     // set field type
     $this->properties['type'] = 'checkbox';
     // set this field as array html dom object
     $this->properties['name'] .= '[]';
     unset($this->properties['value'], $this->properties['id']);
     $build = null;
     foreach ($options as $opt) {
         // check if this is active element
         if (Obj::isArray($this->value) && Arr::in($opt, $this->value)) {
             $this->properties['checked'] = null;
         } else {
             unset($this->properties['checked']);
             // remove checked if it setted before
         }
         $this->properties['value'] = $opt;
         // apply structured checkboxes style for each item
         $build .= App::$View->render('native/form/multi_checkboxes_list', ['item' => self::buildSingleTag('input', $this->properties) . self::nohtml($opt)]);
     }
     return $build;
 }
Ejemplo n.º 3
0
 /**
  * Build <select {$properties} >[<options>]</select> response
  * {@inheritDoc}
  * @see \Ffcms\Core\Helper\HTML\Form\iField::make()
  */
 public function make()
 {
     // get options from properties
     $options = $this->properties['options'];
     unset($this->properties['options']);
     if (!Obj::isIterable($options)) {
         throw new SyntaxException('Select field ' . self::nohtml($this->name) . ' have no iterable options');
     }
     // value is not used there
     unset($this->properties['value']);
     // options is defined as key->value array?
     $optionsKey = $this->properties['optionsKey'] === true;
     unset($this->properties['optionsKey']);
     $buildOpt = null;
     foreach ($options as $optIdx => $opt) {
         $optionProperty = [];
         if ($optionsKey === true) {
             // options with value => text
             $optionProperty['value'] = $optIdx;
             if ($optIdx == $this->value) {
                 $optionProperty['selected'] = null;
                 // def boolean attribute html5
             }
         } else {
             // only value option
             if ($opt == $this->value) {
                 $optionProperty['selected'] = null;
                 // def boolean attribute html5
             }
         }
         $buildOpt .= self::buildContainerTag('option', $optionProperty, $opt);
     }
     // return compiled DOM
     return self::buildContainerTag('select', $this->properties, $buildOpt, true);
 }
Ejemplo n.º 4
0
 /**
  * Build <select @properties>@optionsDOM</select> container 
  * {@inheritDoc}
  * @see \Ffcms\Core\Helper\HTML\Form\iField::make()
  */
 public function make()
 {
     // check if options is defined
     $options = $this->properties['options'];
     $optionsKey = (bool) $this->properties['optionsKey'];
     if (!Obj::isIterable($options)) {
         throw new SyntaxException('Options for field ' . self::nohtml($this->name) . ' is not iterable');
     }
     unset($this->properties['options']);
     // set global field type
     $this->properties['type'] = 'select';
     // add multiple element
     $this->properties['multiple'] = null;
     $this->properties['name'] .= '[]';
     unset($this->properties['value'], $this->properties['options'], $this->properties['optionsKey']);
     // build options as HTML DOM element: <option @value>@text</option>
     $optionsDOM = null;
     foreach ($options as $val => $text) {
         // check if options key is value
         $optionProperty = null;
         if ($optionsKey === true) {
             $optionProperty['value'] = $val;
             // check if current element is active
             if (Obj::isArray($this->value) && Arr::in((string) $val, $this->value)) {
                 $optionProperty['selected'] = 'selected';
             }
         } else {
             if (Obj::isArray($this->value) && Arr::in((string) $text, $this->value)) {
                 $optionProperty['selected'] = 'selected';
             }
         }
         $optionsDOM .= self::buildContainerTag('option', $optionProperty, $text);
     }
     // build <select @properties>@optionsDOM</select>
     return self::buildContainerTag('select', $this->properties, $optionsDOM, true);
 }