GithubHelp home page GithubHelp logo

Comments (10)

RodrigoDornelles avatar RodrigoDornelles commented on July 24, 2024

Note

I did some tests, and realized that the "name" attribute is set correctly when used in columns, but only in a new model, when you go to edit another problem happens.

When create a new model

Works

echo MultipleInput::widget([
    'model' => $model,
    'attribute' => 'campos',
    'columns' => [
        [
            'name' => 'pergunta',
            'type' => 'textarea',
        ],
        [
            'name' => 'opcoes',
            'type'  => MultipleInput::className(),
            'options' => [
                'columns' => [
                    [
                        'name' => 'opcao'
                    ]
                ]
            ]
        ]
    ],
])?>

Related problem

echo MultipleInput::widget([
    'model' => $model,
    'attribute' => 'campos',
    'columns' => [
        [
            'name' => 'pergunta',
            'type' => 'textarea',
        ],
        [
            'name' => 'opcoes',
            'type'  => MultipleInput::className(),
        ]
    ],
])?>
  • name occurred Formulario[campos][1][opcoes][campos[1][opcoes]][0] should be Formulario[campos][1][opcoes][0]
  • id occurred formulario-campos-1-opcoes-campos-1-opcoes-0 should be formulario-1-campos-opcoes-0

When update model

Another problem

echo MultipleInput::widget([
    'model' => $model,
    'attribute' => 'campos',
    'columns' => [
        [
            'name' => 'pergunta',
            'type' => 'textarea',
        ],
        [
            'name' => 'opcoes',
            'type'  => MultipleInput::className(),
            'options' => [
                'columns' => [
                    [
                        'name' => 'opcao'
                    ]
                ]
            ]
        ]
    ],
])?>
  • name occurred Formulario[campos][0][opcoes][opcao][opcao] should be Formulario[campos][0][opcoes][0][item]
  • id occurred formulario-campos-0-opcoes-item-item should be formulario-campos-0-opcoes-0-item

Related problem

echo MultipleInput::widget([
    'model' => $model,
    'attribute' => 'campos',
    'columns' => [
        [
            'name' => 'pergunta',
            'type' => 'textarea',
        ],
        [
            'name' => 'opcoes',
            'type'  => MultipleInput::className(),
        ]
    ],
])?>
  • name occurred Formulario[campos][1][opcoes][campos[1][opcoes]][0] should be Formulario[campos][1][opcoes][0]
  • id occurred formulario-campos-1-opcoes-campos-1-opcoes-0 should be formulario-1-campos-opcoes-0

from yii2-multiple-input.

unclead avatar unclead commented on July 24, 2024

@RodrigoDornelles Hi, thx for the reproduce case. What version of the widget do you use?

from yii2-multiple-input.

RodrigoDornelles avatar RodrigoDornelles commented on July 24, 2024

Hi, thx for the reproduce case. What version of the widget do you use?

@unclead see

packge version
Yii2 2.0.42.1
Jquery 3.5.1
Plugin 2.24.0

from yii2-multiple-input.

unclead avatar unclead commented on July 24, 2024

@RodrigoDornelles I can't reproduce it without seeing the code of the model.

from yii2-multiple-input.

RodrigoDornelles avatar RodrigoDornelles commented on July 24, 2024

I can't reproduce it without seeing the code of the model.

@unclead here

<?php

namespace common\models;

use Yii;
use yii\helpers\Json;

class Formulario extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'formulario';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            //...
            [['campos'], 'safe'],
            [['email_copias'], 'each', 'rule' => ['email']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function beforeSave($insert)
    {
        if (!parent::beforeSave($insert)) {
            return false;
        }

        $this->email_copias = Json::encode($this->email_copias);
        $this->campos = Json::encode($this->campos);
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function afterFind()
    {
        parent::afterFind();
        $this->email_copias = Json::decode($this->email_copias, true);
        $this->campos = Json::decode($this->campos, true);
    }
 }

from yii2-multiple-input.

RodrigoDornelles avatar RodrigoDornelles commented on July 24, 2024

@unclead I did a hardcoded interim fix, this is sufficient for my specific case, but it could be a problem for other cases.

'value' => fn ($data) => isset($data['opcoes'])? $data['opcoes']['item']: null,

from yii2-multiple-input.

unclead avatar unclead commented on July 24, 2024

TBH I didn't manage to reproduce the issue so I can't say why it happens. Did you try to debug it? I mean go to the widget's code and try to figure out the root cause?

from yii2-multiple-input.

RodrigoDornelles avatar RodrigoDornelles commented on July 24, 2024

TBH I didn't manage to reproduce the issue so I can't say why it happens. Did you try to debug it? I mean go to the widget's code and try to figure out the root cause?

I tried debugging and solving, but i found the plugin much more complex than thought.

I'll still work hard on a system, notice anything, or if I can find the problem.

from yii2-multiple-input.

unclead avatar unclead commented on July 24, 2024

but i found the plugin much more complex than thought.

That's true. The result of years of incremental improvements. I'm working on refactoring it's architecture right now and it's quite complicated as well (even considering I did most of the features 😄 )

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.