Skip to content

Commit

Permalink
Showing image error messages
Browse files Browse the repository at this point in the history
The errors are set on the file property which doesn’t have a former field to render it.  So they need to be retrieved.

Fixes #68
  • Loading branch information
weotch committed Jun 23, 2017
1 parent c42d308 commit 764faec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions classes/Fields/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ protected function applyRules()
$live->apply($rules);
}

/**
* Show errors that will have been stored on the `file` proeperty
*
* @return void
*/
public function showErrors()
{
$key = sprintf('images.%s.file', $this->inputId());
if (session('errors') && ($error = session('errors')->first($key))) {
$this->help($error);
$this->group->addClass('has-error');
}
}

/**
* Give the file input the prefixed name.
*
Expand All @@ -126,6 +140,9 @@ public function wrapAndRender()
// Add the aspect ratio choice
$this->group->dataAspectRatio($this->ratio ?: false);

// Set errors
$this->showErrors();

// Inform whether there is an existing image to preview
if ($this->hasImage()) {
$this->group->addClass('has-image');
Expand Down
2 changes: 1 addition & 1 deletion example/app/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Article extends Base
public static $rules = [
'title' => 'required',
'slug' => 'alpha_dash|unique:articles',
'images.image' => 'image',
'images.image' => 'image|dimensions:min_width=10',
'date' => 'required',
];

Expand Down
2 changes: 1 addition & 1 deletion example/resources/views/admin/articles/edit.haml.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.legend= empty($item) ? 'New' : 'Edit'
!= Former::text('title')
!= Former::wysiwyg('body')
!= Former::image('image')
!= Former::image('image')->blockHelp('Used in listings and details')

%fieldset
.legend Other
Expand Down

0 comments on commit 764faec

Please sign in to comment.