2017-06-30 3 views
-1

私はyii2フレームワークが初めてです。yii2の前のフィールドで特定の値を選択した後にフィールドで「必須」を無効にしようとしています

私はフォームを持っていて、前のフィールドで選択した値に基づいて、フィールドで「必須」を非表示にして無効にすることを考えています。

私はjqueryを使用してフィールドを非表示にできましたが、「必須」フィールドを無効にできませんでした。

When i select publish When i select 'Not Publish', the announcement field hidden but when i click create button, nothing happen bacause i have to fill in value in all fields including the hidden one

あなたはそのフィールドの条件付きの検証を適用する必要があり、それはすでに2日かかったので、私は、誰も私を助けることができると思いますし、私はit.Thankあなた

答えて

0

を解決することはできません。 Doc

あなたのモデル

public function rules() 
{ 
    return [ 
     [],//other rules 
     ['your_field', 'required', 'when' => function ($model) { 
       // return true or false according to your condition 
       // server side validation 
     }, 'whenClient' => "function (attribute, value) { 
       return $('#previousField').val() == 'Condition'; 
       // return true of false to disable or enable required condition 
       // client validation 
     }"] 
    ]; 
} 
関連する問題