示例#1
0
 /**
  * Build widget HTML for this form control.
  */
 function build_widget()
 {
     /* Output <input ... /> */
     $attr = array('id' => $this->get('id'), 'type' => $this->_get('input-type'), 'class' => sprintf('button %s', $this->_get('extra-class')));
     if ($this->_get('render-name')) {
         $attr['name'] = $this->get('name');
     }
     $label = $this->get('label');
     if (!is_null($label)) {
         $attr['value'] = $label;
     }
     if ($this->get('disabled')) {
         $attr['disabled'] = 'disabled';
     }
     $widget = new AnewtXHTMLInput($attr);
     /* Optional extra class value */
     $class = $this->_get('class');
     if (!is_null($class)) {
         $widget->add_class($class);
     }
     /* Help text, if any */
     $help = $this->_get('help');
     if (!is_null($help)) {
         $help_text = to_string($help);
         $widget->set_attribute('title', $help_text);
         $widget->add_class('with-help');
     }
     return $widget;
 }
示例#2
0
 function build_widget()
 {
     $value = $this->_get('value');
     if (is_null($value)) {
         $value = "";
     }
     assert('is_string($value); // only plain strings can be used as field value: type: ' . gettype($value));
     $name = $this->get('name');
     $widgets = array();
     if ($this->get('show-img-preview') && $value) {
         $widgets[] = ax_div_class(ax_img_src($this->get('preview-dir') . $value), 'preview');
     } elseif ($this->get('show-link-preview') && $value) {
         $widgets[] = ax_div_class(ax_a_href($value, $this->get('preview-dir') . $value), 'preview');
     }
     $remove_label = $this->_get('remove-label');
     if ($remove_label && $value) {
         $subattr = array('type' => 'checkbox', 'name' => $name . '-remove');
         $widgets[] = new AnewtXHTMLInput(null, $subattr);
         $subattr = array('for' => $name . '-remove');
         $widgets[] = new AnewtXHTMLLabel($remove_label, $subattr);
         $widgets[] = ax_br();
     }
     /* XML tag attributes used both for single line and multiline */
     $attr = array('name' => $this->get('name'), 'id' => $this->get('id'), 'type' => 'file');
     if ($this->_get('readonly')) {
         $attr['readonly'] = 'readonly';
     }
     if ($this->_get('disabled')) {
         $attr['disabled'] = 'disabled';
     }
     $size = $this->_get('size');
     if (!is_null($size)) {
         assert('is_int($size);');
         $attr['size'] = (string) $size;
     }
     $maxlength = $this->_get('maxlength');
     if (!is_null($maxlength)) {
         assert('is_int($maxlength);');
         $attr['maxlength'] = (string) $maxlength;
     }
     $max_file_size = $this->_get('max_file_size');
     if (!is_null($max_file_size)) {
         $subattr = array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => (string) $max_file_size);
         $widgets[] = new AnewtXHMTLInput(null, $subattr);
     }
     $widget = new AnewtXHTMLInput(null, $attr);
     /* Styling */
     $widget->add_class('fileupload');
     if (!$this->_get('required')) {
         $widget->add_class('optional');
     }
     /* Optional extra class value */
     $class = $this->_get('class');
     if (!is_null($class)) {
         $widget->add_class($class);
     }
     /* Help text, if any */
     $help = $this->_get('help');
     if (!is_null($help)) {
         $help_text = to_string($help);
         $widget->set_attribute('title', $help_text);
         $widget->add_class('with-help');
     }
     $widgets[] = $widget;
     /* Add secondary label, if any */
     $secondary_label = $this->_get('secondary-label');
     if (!is_null($secondary_label)) {
         $widgets[] = $secondary_label;
     }
     $out = ax_fragment($widgets);
     return $out;
 }
示例#3
0
 function build_widget()
 {
     /* Convert value to string if possible */
     $value = $this->_get('value');
     if (is_null($value)) {
         $value = "";
     } elseif (is_int($value) || is_float($value)) {
         $value = (string) $value;
     }
     if (!is_string($value)) {
         throw new Exception(sprintf('Text control "%s" can only contain strings or numeric values (%s provided)', $this->get('name'), gettype($value)));
     }
     /* XML tag attributes used both for single line and multiline */
     $attr = array('name' => $this->get('name'), 'id' => $this->get('id'));
     if ($this->_get('readonly')) {
         $attr['readonly'] = 'readonly';
     }
     if ($this->_get('disabled')) {
         $attr['disabled'] = 'disabled';
     }
     /* Now differentiate between single and multiline controls */
     if ($this->_get('multiline')) {
         /* Output textarea element */
         $rows = $this->_get('rows');
         assert('is_int($rows)');
         $attr['rows'] = (string) $rows;
         $columns = $this->_get('columns');
         assert('is_int($columns)');
         $attr['cols'] = (string) $columns;
         $widget = new AnewtXHTMLTextarea($value, $attr);
         /* Styling */
         if (!$this->_get('required')) {
             $widget->add_class('optional');
         }
     } else {
         /* Output input element */
         $is_password = $this->_get('password');
         if ($is_password) {
             $attr['type'] = 'password';
         } else {
             $attr['type'] = 'text';
         }
         if ($this->_get('show-value')) {
             $attr['value'] = $value;
         } else {
             $attr['value'] = '';
         }
         $size = $this->_get('size');
         if (!is_null($size)) {
             assert('is_int($size);');
             $attr['size'] = (string) $size;
         }
         $maxlength = $this->_get('maxlength');
         if (!is_null($maxlength)) {
             assert('is_int($maxlength);');
             $attr['maxlength'] = (string) $maxlength;
         }
         $widget = new AnewtXHTMLInput(null, $attr);
         /* Styling */
         $widget->add_class('text');
         if ($is_password) {
             $widget->add_class('password');
         }
         if (!$this->_get('required')) {
             $widget->add_class('text-optional');
         }
     }
     /* Optional extra class value */
     $class = $this->_get('class');
     if (!is_null($class)) {
         $widget->add_class($class);
     }
     /* Help text, if any */
     $help = $this->_get('help');
     if (!is_null($help)) {
         $help_text = to_string($help);
         $widget->set_attribute('title', $help_text);
         $widget->add_class('with-help');
     }
     /* Add secondary label, if any */
     $secondary_label = $this->_get('secondary-label');
     if (is_null($secondary_label)) {
         $out = $widget;
     } else {
         $out = ax_fragment($widget, $secondary_label);
     }
     return $out;
 }