Yii Framework Forum: Validação no Rules a partir de variável vinda de outro Model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Validação no Rules a partir de variável vinda de outro Model Rate Topic: -----

#1 User is offline   alessandrasouza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 19-December 16
  • Location:Belo Horizonte

Posted 19 December 2016 - 07:32 AM

Bom dia, sou iniciante no Yii e estou com a seguinte duvida, preciso tornar muitos campos obrigatórios pertencentes a um model, se e somente se uma variável vinda de outro model tiver determinado valor, alguém pode me dar uma luz??
0

#2 User is offline   Wanderson 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 20-February 09
  • Location:Rio de Janeiro, Brazil

Posted 19 December 2016 - 05:27 PM

Tente isso:


class Teste extends ActiveRecord
{
    public $campo3;

    public function rules()
    {
        return [
            [['campo1', 'campo2'],'required', 'when' => function ($model) {
                return $model->campo3 === 'aaaa';
            }, 'whenClient' => "function (attribute, value) {
                return $('#seumodelo-campo3').val()  ==  'aaaa';
            }"]
        ];
    }
}


0

#3 User is offline   alessandrasouza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 19-December 16
  • Location:Belo Horizonte

Posted 18 January 2017 - 07:33 AM

View PostWanderson, on 19 December 2016 - 05:27 PM, said:

Tente isso:


class Teste extends ActiveRecord
{
    public $campo3;

    public function rules()
    {
        return [
            [['campo1', 'campo2'],'required', 'when' => function ($model) {
                return $model->campo3 === 'aaaa';
            }, 'whenClient' => "function (attribute, value) {
                return $('#seumodelo-campo3').val()  ==  'aaaa';
            }"]
        ];
    }
}





Wanderson, obrigada pela resposta,
tentei desta forma mais a validação não passou, anexo os dois model, para ver se ajuda a entender meu problema

Attached File(s)


0

#4 User is offline   alessandrasouza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 19-December 16
  • Location:Belo Horizonte

Posted 19 January 2017 - 06:36 AM

View PostWanderson, on 19 December 2016 - 05:27 PM, said:

Tente isso:


class Teste extends ActiveRecord
{
    public $campo3;

    public function rules()
    {
        return [
            [['campo1', 'campo2'],'required', 'when' => function ($model) {
                return $model->campo3 === 'aaaa';
            }, 'whenClient' => "function (attribute, value) {
                return $('#seumodelo-campo3').val()  ==  'aaaa';
            }"]
        ];
    }
}




Bom dia ...
Deu certo, fiz uma adaptações no meu form e funcionou legal... obrigada pela ajuda =)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users