I have a table where the row can be dynamically added and user able to submit the file for any row. I have a question here is how can I validate the file input?
I am using jquery to dynamically add / remove the row:
var row =
"<tr> <input type='hidden' name='Registration_Tag[]'' value='" + Registration_Tag + "'>" +
"<td class='px-6 py-4 whitespace-nowrap'>" +
"<div class='flex items-center'>"+
"<div class='ml-4'>"+
"<div class='text-sm font-medium text-gray-900'>"+
Equipment_Name+
"</div>"+
"</div>"+
"</div>"+
"</td>"+
"<td class='px-6 py-4 whitespace-nowrap'>"+
"<div class='text-sm text-gray-500'>"+
Registration_Tag+
"</div>"+
"</td>"+
"<td class='px-6 py-4 whitespace-nowrap'>"+
"<span"+
"class='px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800'>"+
Equipment_Status+
"</span>"+
"</td>"+
"<td class='py-4 whitespace-nowrap text-sm text-gray-500'>"+
"<div class='flex flex-wrap my-auto mb-6'>"+
"<div class='w-full px-3'>"+
"<input id='grid-password' type='file' placeholder='' name='Equipment_Cert[]'>"+
" <small class='text-danger'>{{ $errors->first('Equipment_Cert') }}</small>"+
"</div>"+
"</div>"+
"</td>"+
"<td class='px-6 py-4 whitespace-nowrap text-right text-sm font-medium'>"+
"<button type='button' class='remove-tr close'>"+
"<span aria-hidden='true'>×</span>"+
"</button>"+
"</td>"+
"</tr>"
$("#Calibration_Table").append(row);
I have tried dot notation like below but still no use for me.
$v = Validator::make($request->all(), [
'Calibration_Location'=>'required',
'Calibration_Category'=>'required',
'Date_of_Calibration' => 'required',
'Next_Due_Date' => 'required',
'Equipment_Cert.*' => 'required'
]);
if ($v->fails()) {
return redirect('/Equipments/create?request_type=Update+Calibration+for+All+Category')
->withErrors($v->errors())
->withInput();
}
Hope can receive some advice from you. Thanks in advance
See Question&Answers more detail:os