Friday, 15 May 2015

forms - Yii2 requirement selection one or more checkboxes FormBuilder -



forms - Yii2 requirement selection one or more checkboxes FormBuilder -

i have registration form created in "yii2 krajee formbuilder". contains 2 checkboxes. @ to the lowest degree 1 of them must selected. validation must carried out on client side, in order not overload page. easy if yii2 contain alternative assign rules required , whenclient checkboxes - unfortunately not possible. other fields(textboxes, selectboxes, can illustration utilize code:

model:

$public $module1; $public $module2; 'module1'=>[ 'type'=>form::input_checkbox, 'name'=>'ak1', 'label'=>'<b>'.yii::t('app','register.module1').'</b>' ], 'module2'=>[ 'type'=>form::input_checkbox, 'name'=>'ak2', 'label'=>'<b>'.yii::t('app','register.module2').'</b>' ] 'textbox1'=>[ 'type'=>form::input_textbox, 'name'=>'tx1', 'label'=>'<b>'.yii::t('app','register.tx1').'</b>' ] [...] [[ 'textbox1', 'texbox2', ],'required','whenclient'=> "function (attribute, value) { homecoming $('#registerform-textbox1').is(':checked') == false && $('#registerform-textbox2').is(':checked') == false;}" ],

it works ..but texboxes. checbox can not assigned required

i used in case, page reloaded

['module1',function ($attribute, $params) { if ($this->module1 == 0 && $this->module2 == 0) { $this->adderror($attribute, 'you have select @ to the lowest degree 1 option'); } }],

typically checkboxes validation carried out this

public function rules ()      {          array ['checboxname', 'compare', 'comparevalue' => true,                'message' => 'you must agree terms , conditions'],          ...      }

but in case can not combine rule compare rule whenclient - responsible function-specifed validation on client side. how can solve problem?

forms validation checkbox yii2

No comments:

Post a Comment