Пример #1
0
 /**
  * Get the error for a field, wrapped in a label
  *
  * @param  InputInterface $field
  * @param  string         $id
  * @param  array          $attributes
  *
  * @return string|boolean
  */
 public function getErrorFor(InputInterface $field, $id, array $attributes = array())
 {
     $error = $this->errors->first($field->getName());
     if ($error) {
         return $this->builder->label($id, $error, $attributes);
     }
     return false;
 }
Пример #2
0
 /**
  * @param string $key
  * @return string
  */
 public static function getErrorMessage($key)
 {
     if (isset(self::$_messages)) {
         $message = self::$_messages->first($key);
         $message = $message ?: self::$_messages->first(self::_dotNotation($key));
         return $message;
     }
     return '';
 }
Пример #3
0
 public function testFormatIsRespected()
 {
     $container = new MessageBag();
     $container->setFormat('<p>:message</p>');
     $container->add('foo', 'bar');
     $container->add('boom', 'baz');
     $this->assertEquals('<p>bar</p>', $container->first('foo'));
     $this->assertEquals(array('<p>bar</p>'), $container->get('foo'));
     $this->assertEquals(array('<p>bar</p>', '<p>baz</p>'), $container->all());
     $this->assertEquals('bar', $container->first('foo', ':message'));
     $this->assertEquals(array('bar'), $container->get('foo', ':message'));
     $this->assertEquals(array('bar', 'baz'), $container->all(':message'));
 }
Пример #4
0
 /**
  * Method to fetch message depending upon it's type
  * @param  MessageBag|string $messages
  * @return string
  */
 protected function fetchMessage($messages)
 {
     if ($messages instanceof MessageBag) {
         return $messages->first();
     } else {
         if (is_string($messages)) {
             return $messages;
         } else {
             return self::MESSAGE;
         }
     }
 }
Пример #5
0
 /**
  * Check for the key in the error manager session else return the message
  * from the message bag
  *
  * @param  string  $key
  * @param  string  $format
  * @return string
  */
 public function first($key = null, $format = null)
 {
     if ($key) {
         if (Session::has('errorManager.errors')) {
             $errors = new parent(Session::get('errorManager.errors'));
             if ($errors->has($key)) {
                 return $errors->first($key);
             }
         }
     }
     return parent::first($key);
 }
Пример #6
0
 /**
  * Test if the form values are valid. It will validate each
  * element and add an error to that element if the validation
  * fails.
  *
  * @param Validator $validator
  */
 protected function validate()
 {
     // If there are no errors, then we don't have to do
     // anything more.
     if (!$this->errors) {
         return $this;
     }
     // Add the errors to the elements
     foreach ($this->getElements() as $name => $element) {
         // For now, we only use the first error
         $error = $this->errors->first($name);
         if ($error) {
             $element->withError()->help($error);
         }
     }
 }
Пример #7
0
 public function getErrorMessage($default = '')
 {
     return $this->errors->first('message') ?: $default;
 }
Пример #8
0
 /**
  * Create a form error helper field.
  *
  * @param string                         $name
  * @param \Illuminate\Support\MessageBag $errors
  * @param string                         $wrap
  *
  * @return string
  */
 protected function errors($name, $errors = null, $wrap = '<span class="help-block">:message</span>')
 {
     if ($errors && $errors->has($name)) {
         return $errors->first($name, $wrap) . "\n";
     }
     return '';
 }
Пример #9
0
 /**
  * Construct the redirection
  */
 private function prv_redirect($type, \Illuminate\Support\MessageBag $messagesBag)
 {
     $strMessages = '';
     if ($messagesBag->count() > 1) {
         $strMessages = '<ul>';
         foreach ($messagesBag as $e) {
             $strMessages .= '<li>' . $e . '</li>';
         }
         $strMessages .= '</ul>';
     } else {
         $strMessages = $messagesBag->first();
     }
     Notification::$type($strMessages);
     if ($type == 'error') {
         return $this->mRedirect->withInput()->withErrors($messagesBag);
     } else {
         return $this->mRedirect;
     }
 }
Пример #10
0
 /**
  * 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())
 {
     $selected = $this->getValueAttribute($name, $selected);
     $options['id'] = $this->getIdAttribute($name, $options);
     if (!isset($options['name'])) {
         $options['name'] = $name;
     }
     // The form-control class should be a default class for every input
     // generated. The class option on the input also overrides every
     // default classes set.
     if (isset($options['class'])) {
         $this->setClass($options['class']);
     }
     $options['class'] = "form-control " . $this->class;
     // Removes keys for the wrapper from the $options array and puts them
     // into variables to prevent them from appearing as attributes on the
     // input itself.
     array_key_exists('label', $options) ? $label = array_pull($options, 'label') : ($label = null);
     $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);
     // Sets the $input variable to the newly generated input field, this
     // variable will then be used within the Bootstrap wrapper instead of
     // being returned directly.
     $input = "<select{$options}>{$list}</select>";
     // If there are errors we want to add the has-error class to the form-group
     // tag to make the border glow red.
     if (!is_null($this->errors) && $this->errors->has($name) && $name != NULL) {
         $this->formGroupClass .= " has-error";
         // If exteded feedback is also enabled we will also add the has-feedback
         // class to allow showing the icons.
         if ($this->feedback === true) {
             $this->formGroupClass .= " has-feedback";
         }
     }
     // The return variable holds the HTML output that is returned to the user.
     // It's purposely divided into lines to allow for better reading and
     // easier conditionals for some of the output.
     $return = '<div class="form-group ' . $this->formGroupClass . '">';
     $return .= '<div class="row">';
     $return .= '<div class="col-md-4">';
     // If a label is given then we show the label here. Notice
     // that the form class is available as IlluminateFormBuilder
     // and not as Form.
     if (!is_null($label)) {
         $return .= IlluminateFormBuilder::label($name, $label);
     }
     $return .= '</div>';
     $return .= '<div class="col-md-8 text-right">';
     // If errors are present we show the error message here.
     // Error styling can be done using the validation-error
     // class that is added automatically.
     if (!is_null($this->errors) && $this->errors->has($name) && $name != NULL) {
         $return .= $this->errors->first($name, '<p class="text-danger validation-error">:message</p>');
     }
     $return .= '</div>';
     $return .= '</div>';
     $return .= $input;
     $return .= '</div>';
     $this->resetConfig();
     return $return;
 }