-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in Multiple columns example #17
Comments
i'll check the example documentation but here is screen from my test app: http://prntscr.com/7wi131 Or you mean that message is not appeared? As workaround you can use errorSummary |
Eugene, thank you for answer. Here is my code. namespace frontend\widgets\menu;
use Yii;
use yii\validators\RequiredValidator;
class Configuration extends \common\models\WidgetsConfig
{
public $items;
//public $title;
public function rules()
{
return [
['items', 'validateItems'],
];
}
public function init()
{
parent::init();
}
public function attributeLabels()
{
return [
'items' => 'Пункты меню',
];
}
public function validateItems($attribute)
{
$requiredValidator = new RequiredValidator();
$requiredValidator->message = 'Необходимо заполнить поле.';
foreach($this->$attribute as $index => $row) {
$error = null;
$requiredValidator->validate($row['label'], $error);
if (!empty($error)) {
$key = $attribute . '[' . $index . '][label]';
$this->addError($key, $error);
}
}
}
public function rolesList()
{
return Yii::$app->authManager->getRoles();
}
} form: use unclead\widgets\MultipleInput;
use yii\helpers\ArrayHelper;
$roles = Yii::$app->authManager->getRoles();
echo $form->field($model, 'items')->widget(MultipleInput::className(), [
'columns' => [
[
'name' => 'label',
'title' => 'Название',
],
[
'name' => 'url',
'title' => 'Ссылка',
'defaultValue' => '/',
],
[
'name' => 'access',
'type' => 'checkboxList',
'title' => 'Доступ',
'items' => ArrayHelper::map($roles, 'name', 'description'),
'options' => [
'item' => function ($index, $label, $name, $checked, $value) {
$render = '<div class="checkbox">
<label>
<input type="checkbox"'.($checked?' checked':'').' name="'.$name.'" value="'.$value.'">
'.$label.'
</label>
</div>';
return $render;
}
],
]
]
])->hint('Если ни одна роль не отмечена, то пункт меню смогут увидеть все пользователи'); May be it not works because the model extends base\Model, not ActiveRecord? |
it not works because widget uses Html helper for rendering the inputs. |
@mikbox74 Try to update to latest revision. I adapted your code. Let me know if all is correct |
I try it with example above. Div.help-block.help-block-error appears but it is empty and field not highlighted. Obviously you forget to put errors from model into the div and add class has-error to div.form-control. |
You use form without Ajax validation. Am I right? I forgot about this use case Отправлено со смартфона Sony Xperia™ Пользователь Michail notifications@github.com писал:
|
Yes, right. 2015-07-25 16:23 GMT+04:00, Eugene Tupikov notifications@github.com:
С уважением, Михаил |
All works fine. Thank you for this incredible widget! |
Sorry for reopen issue, close if you think it is better to create new one. First of all, thanks a lot for such as incredible widget, it fits my need perfectly. I notice errors works fine but error messages are not show. Is it that for missconfiguration of mine or is it an expected behaviour? Ressume: Errors are highlighted, but error messages are not shown |
@daniroyo create a new issue with the code example to reproduce your case |
Sorry, but I finally found the way to show the error, using attribute "enableError" on Column definition like follows.
|
this option is covered in the documentation 😄 |
https://github.com/unclead/yii2-multiple-input/blob/master/docs/multiple_columns.md
This validation example not works
The $error not displays.
I guess it is possible but requires impruvement within the widget code.
The text was updated successfully, but these errors were encountered: