Hi, I am using Yii2 basic.
I have a table called members with fields MemberId, Name, etc. I have another table called memberchildrendata with fields ChildId, MemberId,etc. Also I have created the CRUD’s for same.
The relationship between two tables is one to many so the primary key of members table MemberId is foreign key in the memberchildrendata.
Now I am using dynamic form widget extension in yii2 form.
I have a field DateOfMarriage where I am using jui datepicker in yii2. This field is in memberchildrendata table.
Now I have enabled enableAjaxValidation to this field as shown
<td style="border: 1px solid black;">
<?= $form->field($modelsmemchildren, "[{$i}]DateOfMarriage",['enableAjaxValidation'=>true])->label(false)->widget(DatePicker::classname(), [
'dateFormat' => 'yyyy-MM-dd',
'options' => ['class' => 'form-control picker1']])
?>
</td>
In my Members controller I have used this code,
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
In my Memberschildrendata model, I have a function which validate the DateOfBirth field as
public function validatedate($attribute, $params, $validator)
{
if($this->$attribute==0000-00-00)
$this->addError($attribute,'Date is not good');
}
Now when the user tries to enter the date as 0000-00-00 immediately error should be displayed on the form as Date is not good. In dynamic form widget https://github.com/wbraganca/yii2-dynamicform it is not working. It is accepting the date. How to solve this