Bug:: unsetAddFields

When I use unsetAddFields() , I cannot set a default value as per the documentation.

If I try the below, the value remains empty (unlike the tutorial)

$crud->setTable('orders');
$crud->setSubject('Order', 'Orders');
$crud->unsetAddFields(['status']);
$crud->setRelation('customerNumber','customers','contactLastName');

$crud->callbackBeforeInsert(function ($stateParameters) {
    $stateParameters->data['status'] = 'In Process';

    return $stateParameters;
});

$output =  $crud->render();

If I remove the unsetAddFields method, the code works well…

But the field status is not hidden anymore.

In this case, the function unsetAddFields does not only hide the field, but removes it from the insert routine.

Please help.

Hello @panv ,

Basically you should use the fieldType invisible instead. For security reasons after the version 2.8.0 or later we have implemented the invisible field so you can specify if you would like to specify a specific field that you don’t want to show it to the end user. Invisible field type is used in case you would like to receive the data in a later stage (e.g. insert, update, clone,… e.t.c.)

So for your implementation you should do something like this:

$crud->setSubject('Order', 'Orders');
$crud->fieldTypeAddForm('status', 'invisible');
$crud->setRelation('customerNumber','customers','contactLastName');

$crud->callbackBeforeInsert(function ($stateParameters) {
    $stateParameters->data['status'] = 'In Process';

    return $stateParameters;
});

$output =  $crud->render();

Regards
Johnny

Hello Johnny…
Thank you for your reply…
Please, is this method in community or enterprise ??
When I try to use it, it gives an error…

Error

Call to undefined method App\Libraries\GroceryCrud::fieldTypeAddForm() 

Hello @panv,

You are right, I was referring to Enterprise edition. For community edition use fieldType instead

$crud->fieldType('status', 'hidden');

if you would like to specify it only for the add form do the below:

if ($crud->getState() === 'add') {
	$crud->fieldType('status', 'hidden');
}
1 Like

@johnny … much grateful…

I can’t wait to get back home to apply it.

:beers:

1 Like