GithubHelp home page GithubHelp logo

Comments (13)

unclead avatar unclead commented on June 21, 2024

i'll check the example documentation but here is screen from my test app: http://prntscr.com/7wi131
As you can see validation works fine. Please provide your code, so I checked it

Or you mean that message is not appeared?

As workaround you can use errorSummary

from yii2-multiple-input.

mikbox74 avatar mikbox74 commented on June 21, 2024

Eugene, thank you for answer. Here is my code.
Model:

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?

from yii2-multiple-input.

unclead avatar unclead commented on June 21, 2024

it not works because widget uses Html helper for rendering the inputs.
I'll try to use your solution with some modification for fixing this bug

from yii2-multiple-input.

unclead avatar unclead commented on June 21, 2024

@mikbox74 Try to update to latest revision. I adapted your code. Let me know if all is correct

from yii2-multiple-input.

mikbox74 avatar mikbox74 commented on June 21, 2024

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.

from yii2-multiple-input.

unclead avatar unclead commented on June 21, 2024

You use form without Ajax validation. Am I right? I forgot about this use case

Отправлено со смартфона Sony Xperia™

Пользователь Michail [email protected] писал:

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.


Reply to this email directly or view it on GitHub:
#17 (comment)

from yii2-multiple-input.

mikbox74 avatar mikbox74 commented on June 21, 2024

Yes, right.

2015-07-25 16:23 GMT+04:00, Eugene Tupikov [email protected]:

You use form without Ajax validation. Am I right? I forgot about this use
case

Отправлено со смартфона Sony Xperia™

Пользователь Michail [email protected] писал:

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.


Reply to this email directly or view it on GitHub:
#17 (comment)


Reply to this email directly or view it on GitHub:
#17 (comment)


С уважением, Михаил

from yii2-multiple-input.

unclead avatar unclead commented on June 21, 2024

Fixed via 8ac7f9b
Please check it again and let me know if the issue reproduced
@mikbox74 please check it again. You can get more detail in multiple columns example

from yii2-multiple-input.

mikbox74 avatar mikbox74 commented on June 21, 2024

All works fine. Thank you for this incredible widget!

from yii2-multiple-input.

daniroyo avatar daniroyo commented on June 21, 2024

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

from yii2-multiple-input.

unclead avatar unclead commented on June 21, 2024

@daniroyo create a new issue with the code example to reproduce your case

from yii2-multiple-input.

daniroyo avatar daniroyo commented on June 21, 2024

Sorry, but I finally found the way to show the error, using attribute "enableError" on Column definition like follows.

$form->field($model, 'users')->widget(MultipleInput::class, [
                // 'max' => 4,
                'addButtonPosition' => [
                    MultipleInput::POS_FOOTER,
                    MultipleInput::POS_HEADER,
                ],
                'columns' => [
                    [
                        'name'  => 'username',
                        'title' => Yii::t('app', 'Username'),
                        **'enableError' => true,**
                        'options' => [
                            'class' => '',
                        ],
                    ],
                ]
            ]);

from yii2-multiple-input.

unclead avatar unclead commented on June 21, 2024

this option is covered in the documentation 😄

from yii2-multiple-input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.