Example #1
0
 /**
  * Render a disabled field
  *
  * @param Field $field
  *
  * @return Input
  */
 public function createDisabledField(Field $field)
 {
     $field->disabled();
     return Input::create('text', $field->getName(), $field->getValue(), $field->getAttributes());
 }
Example #2
0
 /**
  * Prints out the current tag
  *
  * @return string An input file tag
  */
 public function render()
 {
     // Maximum file size
     $hidden = $this->maxSize ? HtmlInput::hidden('MAX_FILE_SIZE', $this->maxSize) : null;
     return parent::render() . $hidden;
 }
Example #3
0
 /**
  * Renders a checkable
  *
  * @param string|array $item          A checkable item
  * @param integer   $fallbackValue A fallback value if none is set
  *
  * @return string
  */
 protected function createCheckable($item, $fallbackValue = 1)
 {
     // Extract informations
     extract($item);
     // Set default values
     if (!isset($attributes)) {
         $attributes = array();
     }
     if (isset($attributes['value'])) {
         $value = $attributes['value'];
     }
     if (!isset($value) or $value === $this->app['former']->getOption('unchecked_value')) {
         $value = $fallbackValue;
     }
     // If inline items, add class
     $isInline = $this->inline ? ' ' . $this->app['former.framework']->getInlineLabelClass($this) : null;
     // Merge custom attributes with global attributes
     $attributes = array_merge($this->attributes, $attributes);
     if (!isset($attributes['id'])) {
         $attributes['id'] = $name . $this->unique($name);
     }
     // Create field
     $field = Input::create($this->checkable, $name, $value, $attributes);
     if ($this->isChecked($item, $value)) {
         $field->checked('checked');
     }
     // Add hidden checkbox if requested
     if ($this->isOfType('checkbox', 'checkboxes')) {
         if ($this->isPushed or $this->app['former']->getOption('push_checkboxes') and $this->isPushed !== false) {
             $field = $this->app['former']->hidden($name)->forceValue($this->app['former']->getOption('unchecked_value')) . $field->render();
         }
     }
     // If no label to wrap, return plain checkable
     if (!$label) {
         return is_object($field) ? $field->render() : $field;
     }
     return Element::create('label', $field . $label)->for($attributes['id'])->class($this->checkable . $isInline);
 }
Example #4
0
 public function testCanUseXhtmlStandards()
 {
     Tag::$config['doctype'] = 'xhtml';
     $field = Input::hidden('foo', 'bar');
     $this->assertContains(' />', $field->render());
 }
Example #5
0
 /**
  * Renders a checkable
  *
  * @param string|array $item          A checkable item
  * @param integer      $fallbackValue A fallback value if none is set
  *
  * @return string
  */
 protected function createCheckable($item, $fallbackValue = 1)
 {
     // Extract informations
     extract($item);
     // Set default values
     if (!isset($attributes)) {
         $attributes = array();
     }
     if (isset($attributes['value'])) {
         $value = $attributes['value'];
     }
     if (!isset($value) or $value === $this->app['former']->getOption('unchecked_value')) {
         $value = $fallbackValue;
     }
     // If inline items, add class
     $isInline = $this->inline ? ' ' . $this->app['former.framework']->getInlineLabelClass($this) : null;
     // In Bootsrap 3, don't append the the checkable type (radio/checkbox) as a class if
     // rendering inline.
     $class = $this->app['former']->framework() == 'TwitterBootstrap3' ? trim($isInline) : $this->checkable . $isInline;
     // Merge custom attributes with global attributes
     $attributes = array_merge($this->attributes, $attributes);
     if (!isset($attributes['id'])) {
         $attributes['id'] = $name . $this->unique($name);
     }
     // Create field
     $field = Input::create($this->checkable, $name, $value, $attributes);
     if ($this->isChecked($item, $value)) {
         $field->checked('checked');
     }
     // Add hidden checkbox if requested
     if ($this->isOfType('checkbox', 'checkboxes')) {
         if ($this->isPushed or $this->app['former']->getOption('push_checkboxes') and $this->isPushed !== false) {
             $field = $this->app['former']->hidden($name)->forceValue($this->app['former']->getOption('unchecked_value')) . $field->render();
             // app['former.field'] was overwritten by Former::hidden() call in the line above, so here
             // we reset it to $this to enable $this->app['former']->getErrors() to retrieve the correct object
             $this->app->instance('former.field', $this);
         }
     }
     // If no label to wrap, return plain checkable
     if (!$label) {
         $element = is_object($field) ? $field->render() : $field;
     } else {
         $element = Element::create('label', $field . $label)->for($attributes['id'])->class($class)->render();
     }
     // If BS3, if checkables are stacked, wrap them in a div with the checkable type
     if (!$isInline && $this->app['former']->framework() == 'TwitterBootstrap3') {
         $wrapper = Element::create('div', $element)->class($this->checkable);
         if ($this->getAttribute('disabled')) {
             $wrapper->addClass('disabled');
         }
         $element = $wrapper->render();
     }
     // Return the field
     return $element;
 }
Example #6
0
 /**
  * Outputs a hidden field
  *
  * @return string An <input type="hidden" />
  */
 public function render()
 {
     return HtmlInput::create('hidden', $this->name, $this->value, $this->attributes)->render();
 }
Example #7
0
 /**
  * Outputs a hidden field
  *
  * @return string An <input type="hidden" />
  */
 public function render()
 {
     return HtmlInput::create('hidden', $this->name, Helpers::encode($this->value), $this->attributes)->render();
 }
 public function testCanHaveSelfClosingChildren()
 {
     $tag = Element::div('foo')->nest(array('foo' => Input::create('text')));
     $this->assertEquals('<div>foo<input type="text"></div>', $tag->render());
 }
Example #9
0
 public function testMinCanBeZero()
 {
     $input = Input::create('number', 'foo', 0)->min(0)->max(100)->render();
     $matcher = '<input type="number" name="foo" min="0" max="100" value="0">';
     $this->assertEquals($matcher, $input);
 }