Exemplo n.º 1
0
 /**
  * Register the form builder instance.
  *
  * @return void
  */
 protected function registerFormBuilder()
 {
     $this->app->bindShared('form', function ($app) {
         $form = new FormBuilder($app['html'], $app['url'], $app['session.store']->getToken());
         return $form->setSessionStore($app['session.store']);
     });
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('form', function ($app) {
         $form = new FormBuilder($app['html'], $app['url'], $app['session.store']->getToken());
         return $form->setSessionStore($app['session.store']);
     });
     $this->app->singleton('html', function ($app) {
         return new HtmlBuilder($app['url']);
     });
 }
 /**
  * Add Laravel Form to container if not already set
  */
 private function registerFormIfHeeded()
 {
     if (!$this->app->offsetExists('form')) {
         $this->app->bindShared('form', function ($app) {
             $form = new LaravelForm($app['html'], $app['url'], $app['session.store']->getToken());
             return $form->setSessionStore($app['session.store']);
         });
         if (!$this->aliasExists('Form')) {
             AliasLoader::getInstance()->alias('Form', 'Illuminate\\Html\\FormFacade');
         }
     }
 }
 public function button($value = null, $options = array())
 {
     if (strpos(@$options['class'], 'btn') === false) {
         @($options['class'] .= ' btn btn-default');
     }
     return parent::password($value, $options);
 }
Exemplo n.º 5
0
 /**
  * Render the form for a given action or the default form.
  *
  * @param  string $action
  * @param  array  $attributes
  *
  * @return string
  */
 public function render($action = null, array $attributes = array())
 {
     $renderer = $this->getRenderer();
     $html = $this->open($action, $attributes);
     $html .= $renderer->render($this->getFields());
     $html .= $this->builder->close();
     return $html;
 }
Exemplo n.º 6
0
 /**
  * Get the label for a field
  *
  * @param  InputInterface $field
  * @param  string         $id
  * @param  array          $attributes
  *
  * @return string|boolean
  */
 public function getLabelFor(InputInterface $field, $id, array $attributes = array())
 {
     $label = $field->getLabel();
     if ($label) {
         return $this->builder->label($id, $label, $attributes);
     }
     return false;
 }
Exemplo n.º 7
0
    public function close()
    {
        return sprintf('<div class="form-group">
				<button type="submit"
					class="btn btn-success btn-block btn-loading"
					data-loading="<span class=\'glyphicon glyphicon-refresh spinning\'></span>">حفظ
				</button>
			</div>%s', parent::close());
    }
 /**
  * Create the input group for an element with the correct classes for errors.
  *
  * @param  string  $type
  * @param  string  $name
  * @param  string  $label
  * @param  string  $value
  * @param  array   $options
  * @return string
  */
 public function input($type, $name, $label = null, $value = null, $options = array())
 {
     $label = $this->getLabelTitle($label, $name);
     $options = $this->getFieldOptions($options);
     $wrapperOptions = array('class' => $this->getRightColumnClass());
     $inputElement = $type == 'password' ? $this->form->password($name, $options) : $this->form->{$type}($name, $value, $options);
     $groupElement = '<div ' . $this->html->attributes($wrapperOptions) . '>' . $inputElement . $this->getFieldError($name) . '</div>';
     return $this->getFormGroup($name, $label, $groupElement);
 }
 /**
  * Create a select box field.
  *
  * @param  string  $name
  * @param  array   $list
  * @param  string  $selected
  * @param  array   $options
  * @return string
  */
 public function select($name, $list = array(), $selected = null, $options = array(), $label = '')
 {
     if (!self::$is_bootstrap) {
         return parent::select($name, $list, $selected, $options);
     }
     $label_text = $label == '' ? $this->transformKey($name) : $label;
     $options = $this->appendClassToOptions('form-control', $options);
     // Call the parent select method so that Laravel can handle
     // the rest of the select set up.
     return $this->openGroup($name, $label_text) . parent::select($name, $list, $selected, $options) . $this->closeGroup($name);
 }
Exemplo n.º 10
0
 /**
  * @param Field $field
  * @param string $type
  * @return string
  */
 public function buttonField(Field $field, $type = 'button')
 {
     $attributes = $field->getAttributes();
     $attributes['type'] = $type;
     if ($field->label) {
         $value = $field->label;
         $attributes['value'] = $field->value;
     } else {
         $value = $field->value;
     }
     return $this->builder->button($value, $attributes);
 }
Exemplo n.º 11
0
 /**
  * Generate a select field.
  *
  * @param        $name
  * @param string $value
  * @param array  $options
  *
  * @return string
  */
 public function select($name, $value = null, $options = [])
 {
     $select_options = [];
     // Loop through, and pluck out the select box list options
     // from the $options array, then remove the select options.
     foreach ($options as $key => $label) {
         if (is_array($label)) {
             $select_options = $label;
             unset($options[$key]);
         }
     }
     return $this->formBuilder->select($name, $select_options, $value, $options);
 }
Exemplo n.º 12
0
 /**
  * Open up a new HTML form and includes a session key.
  * @param array $options
  * @return string
  */
 public function open(array $options = [])
 {
     $method = strtoupper(array_get($options, 'method', 'post'));
     $request = array_get($options, 'request');
     $model = array_get($options, 'model');
     if ($model) {
         $this->model = $model;
     }
     $append = $this->requestHandler($request);
     if ($method != 'GET') {
         $append .= $this->sessionKey(array_get($options, 'sessionKey'));
     }
     return parent::open($options) . $append;
 }
Exemplo n.º 13
0
 /**
  * Create a form select field.
  *
  * @param string                         $name
  * @param string                         $label
  * @param array                          $list
  * @param string                         $selected
  * @param \Illuminate\Support\MessageBag $errors
  * @param array                          $options
  *
  * @return string
  */
 protected function options($name, $label = null, array $list = array(), $selected = null, $errors = null, array $options = array())
 {
     $options = array_merge(array('class' => 'form-control'), $options);
     $return = $this->group($name, $errors);
     $return .= $this->label($name, $label);
     if ($this->formType == self::FORM_HORIZONTAL) {
         $return .= $this->group('', null, $this->inputClass);
     }
     $return .= $this->form->select($name, $list, $selected, $options) . "\n";
     $return .= $this->errors($name, $errors);
     if ($this->formType == self::FORM_HORIZONTAL) {
         $return .= '</div>' . "\n";
     }
     $return .= '</div>' . "\n";
     return $return;
 }
Exemplo n.º 14
0
 public function testElements()
 {
     $this->getApplicationMock()->expects($this->exactly(1))->method('make')->with('form')->will($this->returnValue($this->formBuilderMock));
     $this->testInstance->setMeta($this->metaAttributesMock);
     $this->metaAttributesMock->__value = uniqid();
     $this->metaAttributesMock->setLocale('_');
     $testMethods = ['open', 'select', 'close', 'submit', 'hidden', 'checkbox', 'radio', 'text', 'password', 'textarea'];
     foreach ($testMethods as $testMethod) {
         $this->formBuilderMock->expects($this->exactly(1))->method($testMethod);
     }
     $this->assertSame("<label>label</label>", (string) $this->testInstance->label('label'));
     $this->testInstance->open();
     $this->testInstance->close();
     $this->testInstance->select('value');
     $this->testInstance->submit('value');
     $this->testInstance->hidden('value');
     $this->testInstance->checkbox('value');
     $this->testInstance->radio('value');
     $this->testInstance->text('value');
     $this->testInstance->textarea('value');
     $this->testInstance->password('value');
 }
Exemplo n.º 15
0
 /**
  * Prepare data grid columns.
  *
  * @param  bool  $results
  * @return array
  */
 protected function prepareColumns($model)
 {
     $el = [];
     foreach ($this->dataGridColumns as $attributes) {
         $type = array_pull($attributes, 'type');
         if ($type) {
             if ($type === 'a') {
                 $elementContent = '<%= r.' . array_pull($attributes, 'content') . ' %>';
                 $link = $this->html->decode($this->html->link('#', $elementContent, $attributes));
                 $link = str_replace('href="#"', 'href="<%= r.edit_uri %>"', $link);
                 $el[] = $link;
             } elseif ($type === 'checkbox') {
                 $checkBoxName = array_pull($attributes, 'name');
                 $value = array_pull($attributes, 'value');
                 $value = '<%= r.' . $value . ' %>';
                 $el[] = $this->html->decode($this->form->checkbox($checkBoxName, $value, null, $attributes));
             }
         } else {
             $el[] = '<%= r.' . array_pull($attributes, 'content') . ' %>';
         }
     }
     return $el;
 }
Exemplo n.º 16
0
 /**
  * Create a form select field.
  *
  * @param string                         $name
  * @param string                         $label
  * @param array                          $list
  * @param string                         $selected
  * @param \Illuminate\Support\MessageBag $errors
  * @param array                          $options
  *
  * @return string
  */
 protected function options($name, $label = null, array $list = array(), $selected = null, $errors = null, array $options = array())
 {
     $return = '';
     $options = array_merge(array('class' => 'form-control', 'id' => $name), $options);
     $containerAttributes = $this->getContainerAttributes($options);
     $labelAttributes = $this->getLabelAttributes($options);
     if (!isset($containerAttributes['display'])) {
         $return .= $this->group($name, $errors, 'form-group', $containerAttributes);
     }
     $return .= $this->label($name, $label, $labelAttributes);
     if ($this->formType == self::FORM_HORIZONTAL) {
         $return .= $this->group('', null, $this->inputClass);
     }
     $return .= $this->form->select($name, $list, $selected, $options) . "\n";
     $return .= $this->errors($name, $errors);
     if ($this->formType == self::FORM_HORIZONTAL) {
         $return .= '</div>' . "\n";
     }
     if (!isset($containerAttributes['display'])) {
         $return .= '</div>' . "\n";
     }
     return $return;
 }
Exemplo n.º 17
0
 /**
  * Creates a color element
  *
  * @param string $name The name of the element
  * @param null   $value
  * @param array  $attributes
  * @return string
  */
 public function color($name, $value = null, $attributes = array())
 {
     $attributes['class'] = isset($attributes['class']) ? self::FORM_CONTROL . ' ' . $attributes['class'] : self::FORM_CONTROL;
     return parent::input('color', $name, $value, $attributes);
 }
Exemplo n.º 18
0
 /**
  * Checks if macro is registered
  *
  * @param string $name
  * @return boolean 
  * @static 
  */
 public static function hasMacro($name)
 {
     return \Illuminate\Html\FormBuilder::hasMacro($name);
 }
Exemplo n.º 19
0
 /**
  * @param string $name
  * @param array $attributes
  * @return null|string
  */
 public function getIdAttribute($name, $attributes)
 {
     if ($id = parent::getIdAttribute($name, $attributes)) {
         return $id;
     }
     if (Arr::get($attributes, 'type') !== 'hidden') {
         return $name;
     }
     return null;
 }
Exemplo n.º 20
0
 /**
  * Builds the label html
  *
  * @param  string  $name The name of the html field
  * @param  string  $label The label name
  * @param  array   $attributes
  * @return string
  */
 private function buildLabel($name, $label = '', $attributes = array())
 {
     $out = '';
     if (!empty($label)) {
         if (!empty($attributes['class'])) {
             $attributes['class'] .= ' control-label';
         } else {
             $attributes['class'] = 'control-label';
         }
         if ($this->getOption('requiredLabel') and substr($label, -strlen($this->getOption('requiredLabel'))) == $this->getOption('requiredLabel')) {
             $label = $this->getOption('requiredPrefix') . str_replace($this->getOption('requiredLabel'), '', $label) . $this->getOption('requiredSuffix');
             $attributes['class'] .= ' ' . $this->getOption('requiredClass');
         }
         $name = $this->getOption('idPrefix') . $name;
         $out .= parent::label($name, $label, $attributes);
     }
     return $out;
 }
Exemplo n.º 21
0
 /**
  * Set the session store implementation.
  *
  * @param \Illuminate\Session\Store $session
  * @return \Illuminate\Html\FormBuilder 
  * @static 
  */
 public static function setSessionStore($session)
 {
     return \Illuminate\Html\FormBuilder::setSessionStore($session);
 }
Exemplo n.º 22
0
 /**
  * Create a select box field with empty option support.
  * @param  string  $name
  * @param  array   $list
  * @param  string  $selected
  * @param  array   $options
  * @return string
  */
 public function select($name, $list = [], $selected = null, $options = [])
 {
     if (array_key_exists('emptyOption', $options)) {
         $list = ['' => $options['emptyOption']] + $list;
     }
     return parent::select($name, $list, $selected, $options);
 }
Exemplo n.º 23
0
 /**
  * Create a textarea input.
  *
  * @param  string  $name
  * @param  string  $value
  * @param  array   $options
  *
  * @return string
  */
 public function textarea($name, $value = null, $options = [])
 {
     $this->addErrorClass($name, $options);
     $tags['input'] = parent::textarea($name, $value, $options);
     $tags['error'] = $this->getErrorTag($name);
     return $this->buildTags($tags);
 }
Exemplo n.º 24
0
 public function select($name, $list = [], $selected = null, $options = [])
 {
     $options = array_merge($options, $this->parsley->getFieldRules($name));
     return parent::select($name, $list, $selected, $options);
 }
Exemplo n.º 25
0
 /**
  * Create a radio button input field.
  *
  * @param  string  $name
  * @param  mixed   $value
  * @param  bool    $checked
  * @param  array   $options
  * @return string
  */
 public function radio($name, $value = null, $checked = null, $options = array())
 {
     $this->appendReadOnly($options);
     return parent::radio($name, $value, $checked, $options);
 }
 /**
  * Create a checkable input field.
  *
  * @param  string $type
  * @param  string $name
  * @param  mixed  $value
  * @param  bool   $checked
  * @param  array  $options
  * @return string
  */
 protected function checkable($type, $name, $value, $checked, $options)
 {
     $options = $this->addErrorClass($name, $options);
     $options = $this->checkRequired($name, $options);
     return parent::checkable($type, $name, $value, $checked, $options);
 }
Exemplo n.º 27
0
 /**
  * Create a button element.
  *
  * @param  string  $value
  * @param  array   $options
  * @return string
  */
 public function button($value = null, $options = array())
 {
     $options = $this->appendClassToOptions('btn', $options);
     return parent::button($value, $options);
 }
Exemplo n.º 28
0
 * Create a select box field.
 *
 * @param  string  $name
 * @param  array   $list
 * @param  string  $selected
 * @param  array   $options
 * @return string
 */
FormBuilder::macro('selectMy', function ($name, $list = array(), $selected = null, $option = '', $options = array()) {
    // When building a select box the "value" attribute is really the selected one
    // so we will use that when checking the model or session for a value which
    // should provide a convenient method of re-populating the forms on post.
    $selected = $this->getValueAttribute($name, $selected);
    $options['id'] = $this->getIdAttribute($name, $options);
    if (!isset($options['name'])) {
        $options['name'] = $name;
    }
    // We will simply loop through the options and build an HTML value for each of
    // them until we have an array of HTML declarations. Then we will join them
    // all together into one single HTML element that can be put on the form.
    $html = array();
    foreach ($list as $value => $display) {
        $html[] = $this->getSelectOption($display, $value, $selected);
    }
    // Once we have all of this HTML, we can join this into a single element after
    // formatting the attributes into an HTML "attributes" string, then we will
    // build out a final select statement, which will contain all the values.
    $options = $this->html->attributes($options);
    $list = implode('', $html);
    return "<select{$options}>{$option}{$list}</select>";
});
Exemplo n.º 29
0
 public function busqueda($params)
 {
     $this->buscando = true;
     return parent::open($params);
 }
Exemplo n.º 30
0
 public function __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken)
 {
     parent::__construct($html, $url, $csrfToken);
     $this->lang = app('translator');
 }