[Bug] Unable to save empty input with relation HasOne
See original GitHub issueBug report
What I did
Sometimes it is necessary to delete data from input with relation HasOne
I try to store at least one input blank from the list:
$this->crud->addFields([
[
'name' => 'userInfo.first_name',
'label' => __('First name'),
'type' => 'text',
'tab' => __('User info'),
'wrapper' => [
'class' => 'form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3',
],
],[
'name' => 'userInfo.last_name',
'label' => __('Last name'),
'type' => 'text',
'tab' => __('User info'),
'wrapper' => [
'class' => 'form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3',
],
],[
'name' => 'userInfo.hrp_number',
'label' => __('HRP - number'),
'type' => 'text',
'tab' => __('User info'),
'wrapper' => [
'class' => 'form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3',
],
],[
'name' => 'userInfo.approved_hrp',
'label' => __('HRP approved'),
'type' => 'select_from_array',
'tab' => __('User info'),
'options' => UserInfo::getStatusValues(),
'allows_null' => false,
'default' => UserInfo::STATUS_APPROVE_PENDING,
'wrapper' => [
'class' => 'form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3',
],
],[
'name' => 'userInfo.address',
'label' => __('Address'),
'type' => 'text',
'tab' => __('User info'),
'wrapper' => [
'class' => 'form-group col-xs-12 col-sm-12 col-md-6 col-lg-6',
],
],[
'name' => 'userInfo.private_mobile',
'label' => __('Private mobile'),
'type' => 'text',
'tab' => __('User info'),
'wrapper' => [
'class' => 'form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3',
],
],[
'name' => 'userInfo.date_of_birth',
'label' => __('Birthday'),
'type' => 'date',
'format' => 'd/m/Y',
'tab' => __('User info'),
'wrapper' => [
'class' => 'form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3',
],
],
]);
What I expected to happen
I expected to see an empty field when I delete data from it
What happened
Data in input can only be written, changed but not deleted. I want to be able to delete data from the input field.
What I’ve already tried to fix it
I was looking for a solution on the Internet, in the official documentation, stackowerflow and other resources, but could not find anything
Is it a bug in the latest version of Backpack?
After I run composer update backpack/crud
the bug… is it still there?
Yes
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version
the output is:
PHP VERSION:
PHP 8.0.10 (cli) (built: Sep 3 2021 17:04:26) ( NTS ) Copyright © The PHP Group Zend Engine v4.0.10, Copyright © Zend Technologies
LARAVEL VERSION:
v8.70.2@dec9524cd0f9fa35a6eb8e25d0b40f8bbc8ec225
BACKPACK VERSION:
4.1.60@bec5cfa11f0cd0712c79256748acf5850080c0ee
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
@CinexUA another idea that I workaround for this issue. As I know this field can be cleared, I reverse
ConvertsEmptyStringsToNull
with the methodInspired by
handlePasswordInput
, inUserCrudController.php
I tried$request->request->set('profile.address_2', '');
but it is not working. So, I just working on the array.Apply it like
handlePasswordInput
Hope it helps 😃
@tabacitu @pxpm Maybe another field attribute
allows_null
orallow_clear
to tell which field needs to reverseConvertsEmptyStringsToNull
? Just a wild idea. XDHi @CinexUA ,
In short, Backpack v4.2 == Backpack 5.0. But it should be a free upgrade for you, if you purchased Backpack after Feb 9th 2021. You can read more about that here. And the upgrade process itself shouldn’t be a long one at all.
Cheers!