I have an odd problem,
I need to generate and show a unique id on the add from before the record is initially saved. To do this I am using callback add form, this basically created a new id in a separate id table and then adds this id into the form field.
Problem is if you then save that record and then add another the add form opens and has not refreshed the field with a new id it seems to have cached the last one, but the callbackAddForm should run the code everytime the add form is opened new?
If I close the add form, refresh the page then add form again then it adds a new id to the field.
Am I going about this in the wrong way?
$crud->callbackAddForm(function ($data) {
$AppGIdsModel = new AppGIdsModel();
$indata = [
'g_id_used' => 1
];
$AppGIdsModel->save($indata);
$db = \Config\Database::connect();
$builder = $db->table('app_g_ids');
$builder->selectMax('id');
$query = $builder->get();
$row = $query->getRow();
if (isset ($row)) {
$data['record_patch_number'] = 'G' . $row->id;
}
return $data;
});
