0

I have a form with multiple reference for a class(I mean table) in single form like add more details. Main goal of the task is a company have more than one users. each user have some access restrictions. so while adding company we will add multiple company users. company users form have that access radio button. here radio button validation is not working. same issue for checkbox and dropdown also.sample code given below. Please help.

AccessController.php

class AccessController extends Controller
{
  public function actionCreate() {
    $formDetails = Yii::$app->request->post('ClientAllowAccess', []);
    if(!empty($formDetails)){
      foreach ($formDetails as $i => $formDetail) {
          $modelDetail = new ClientAllowAccess(['scenario' => ClientAllowAccess::SCENARIO_BATCH_UPDATE]);
          $modelDetail->setAttributes($formDetail);
          $modelClientAccess[] = $modelDetail;
      }
    } else {
      $modelClientAccess[] = new ClientAllowAccess(['scenario' => ClientAllowAccess::SCENARIO_BATCH_UPDATE]);
    }

    return $this->render('create', [
      'client_allow_access_multiple' => $modelClientAccess
    ]);
}
}

create.php

....
    <?php foreach($client_allow_access_multiple as $i => $client_allow_acces): ?>
      <?= $form->field($client_allow_access, '[$i]access_type')->radioList([1 => 'Allow access', 2 => 'Can\'t allow access'],[ 'item' => function($index, $label, $name, $checked, $value) {
           $return = '<label class="modal-radio">';
           $return .= '<input type="radio" name="' . $name . '" value="' . $value . '" id="custom_id_value_'.$index.'" >';
           $return .= '<span>  ' . ucwords($label) . '</span>';
           $return .= '</label>';
           return $return;
        }]); ?>
    <?php endforeach; ?>
....

rendered view

    <div class="form-group field-clientcontactdetails-0-gender has-success">
            <label class="control-label" for="clientcontactdetails-0-gender">Gender</label>
            <select id="clientcontactdetails-0-gender" class="form-control" name="ClientContactDetails[0][gender]">
                <option value="">---</option>
                <option value="1">Male</option>
                <option value="2">Female</option>
                <option value="3">Others</option>
            </select>

 <div class="help-block"></div>
</div>
<div class="form-group field-clientallowaccess-0-access_type required">
            <label class="control-label" for="clientallowaccess-0-access_type">Access Type</label>
            <input type="hidden" name="ClientAllowAccess[0][access_type]" value=""><div id="clientallowaccess-0-access_type"><label><input type="radio" name="ClientAllowAccess[0][access_type]" value="1"> Allow access</label>
                <label><input type="radio" name="ClientAllowAccess[0][access_type]" value="2"> Can't allow access</label></div>
            <div class="help-block"></div>
</div>
Manikandan S
  • 902
  • 1
  • 8
  • 18

0 Answers0