Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
c15aceb0
Commit
c15aceb0
authored
Apr 22, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored filter error display for GridView.
parent
7ca1be35
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
12 deletions
+40
-12
ErrorHandler.php
framework/base/ErrorHandler.php
+1
-1
DataColumn.php
framework/grid/DataColumn.php
+12
-6
GridView.php
framework/grid/GridView.php
+23
-4
BaseHtml.php
framework/helpers/BaseHtml.php
+4
-1
No files found.
framework/base/ErrorHandler.php
View file @
c15aceb0
...
...
@@ -46,7 +46,7 @@ abstract class ErrorHandler extends Component
/**
* Register this errorhandler
* Register this error
handler
*/
public
function
register
()
{
...
...
framework/grid/DataColumn.php
View file @
c15aceb0
...
...
@@ -141,16 +141,22 @@ class DataColumn extends Column
{
if
(
is_string
(
$this
->
filter
))
{
return
$this
->
filter
;
}
elseif
(
$this
->
filter
!==
false
&&
$this
->
grid
->
filterModel
instanceof
Model
&&
$this
->
attribute
!==
null
&&
$this
->
grid
->
filterModel
->
isAttributeActive
(
$this
->
attribute
))
{
if
(
$this
->
grid
->
filterModel
->
hasErrors
(
$this
->
attribute
))
{
Html
::
addCssClass
(
$this
->
filterOptions
,
'has-error'
);
}
$model
=
$this
->
grid
->
filterModel
;
if
(
$this
->
filter
!==
false
&&
$model
instanceof
Model
&&
$this
->
attribute
!==
null
&&
$model
->
isAttributeActive
(
$this
->
attribute
))
{
if
(
$model
->
hasErrors
(
$this
->
attribute
))
{
Html
::
addCssClass
(
$this
->
filterOptions
,
'has-error'
);
$error
=
Html
::
error
(
$model
,
$this
->
attribute
,
$this
->
grid
->
filterErrorOptions
);
}
else
{
$error
=
''
;
}
if
(
is_array
(
$this
->
filter
))
{
$options
=
array_merge
([
'prompt'
=>
''
],
$this
->
filterInputOptions
);
return
Html
::
activeDropDownList
(
$
this
->
grid
->
filterModel
,
$this
->
attribute
,
$this
->
filter
,
$options
)
;
return
Html
::
activeDropDownList
(
$
model
,
$this
->
attribute
,
$this
->
filter
,
$options
)
.
' '
.
$error
;
}
else
{
return
Html
::
activeTextInput
(
$
this
->
grid
->
filterModel
,
$this
->
attribute
,
$this
->
filterInputOptions
)
;
return
Html
::
activeTextInput
(
$
model
,
$this
->
attribute
,
$this
->
filterInputOptions
)
.
' '
.
$error
;
}
}
else
{
return
parent
::
renderFilterCellContent
();
...
...
framework/grid/GridView.php
View file @
c15aceb0
...
...
@@ -15,7 +15,6 @@ use yii\helpers\Url;
use
yii\helpers\Html
;
use
yii\helpers\Json
;
use
yii\widgets\BaseListView
;
use
yii\helpers\ArrayHelper
;
use
yii\base\Model
;
/**
...
...
@@ -142,6 +141,9 @@ class GridView extends BaseListView
* Both "format" and "label" are optional. They will take default values if absent.
*/
public
$columns
=
[];
/**
* @var string the HTML display when the content of a cell is empty
*/
public
$emptyCell
=
' '
;
/**
* @var \yii\base\Model the model that keeps the user-entered filter data. When this property is set,
...
...
@@ -161,6 +163,9 @@ class GridView extends BaseListView
* as GET parameters to this URL.
*/
public
$filterUrl
;
/**
* @var string additional jQuery selector for selecting filter input fields
*/
public
$filterSelector
;
/**
* @var string whether the filters should be displayed in the grid view. Valid values include:
...
...
@@ -175,18 +180,29 @@ class GridView extends BaseListView
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$filterRowOptions
=
[
'class'
=>
'filters'
];
/**
* @var array the options for rendering the filter error summary.
* Please refer to [[Html::errorSummary()]] for more details about how to specify the options.
* @see renderErrors()
*/
public
$filterErrorSummaryOptions
=
[
'class'
=>
'error-summary'
];
/**
* @var array the options for rendering every filter error message.
* This is mainly used by [[Html::error()]] when rendering an error message next to every filter input field.
*/
public
$filterErrorOptions
=
[
'class'
=>
'help-block'
];
/**
* @var string the layout that determines how different sections of the list view should be organized.
* The following tokens will be replaced with the corresponding section contents:
*
* - `{summary}`: the summary section. See [[renderSummary()]].
* - `{errors}`: the filter model error
s
. See [[renderErrors()]].
* - `{errors}`: the filter model error
summary
. See [[renderErrors()]].
* - `{items}`: the list items. See [[renderItems()]].
* - `{sorter}`: the sorter. See [[renderSorter()]].
* - `{pager}`: the pager. See [[renderPager()]].
*/
public
$layout
=
"
{
summary}\n{
errors}\n{
items}\n{pager
}
"
;
public
$layout
=
"
{
summary}\n{items}\n{pager
}
"
;
/**
* Initializes the grid view.
...
...
@@ -233,12 +249,15 @@ class GridView extends BaseListView
public
function
renderErrors
()
{
if
(
$this
->
filterModel
instanceof
Model
&&
$this
->
filterModel
->
hasErrors
())
{
return
Html
::
tag
(
'div'
,
Html
::
ul
(
$this
->
filterModel
->
getFirstErrors
(),
[
'class'
=>
'help-block'
]),
[
'class'
=>
'has-error'
]
);
return
Html
::
errorSummary
(
$this
->
filterModel
,
$this
->
filterErrorSummaryOptions
);
}
else
{
return
''
;
}
}
/**
* @inheritdoc
*/
public
function
renderSection
(
$name
)
{
switch
(
$name
)
{
...
...
framework/helpers/BaseHtml.php
View file @
c15aceb0
...
...
@@ -1047,7 +1047,10 @@ class BaseHtml
public
static
function
errorSummary
(
$models
,
$options
=
[])
{
$lines
=
[];
foreach
((
array
)
$models
as
$model
)
{
if
(
!
is_array
(
$models
))
{
$models
=
[
$models
];
}
foreach
(
$models
as
$model
)
{
/** @var Model $model */
foreach
(
$model
->
getFirstErrors
()
as
$error
)
{
$lines
[]
=
Html
::
encode
(
$error
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment