Crud: Repeatable field return '[]' string after deleting all entries

Created on 14 May 2020  路  4Comments  路  Source: Laravel-Backpack/CRUD

Bug report

What I did

  • I defined a repeatable field
  • I entered some entries
  • I saved the entity
  • then I edited the repeatable field deleting ALL the entries
  • I saved the entity

What I expected to happen

I expected to get a null value as if the repeatable field had never been compiled.

What happened

The field return a string (2) "[]"

What I've already tried to fix it

Asking if this is the expected behavior

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 7.3.15 (cli) (built: Feb 18 2020 12:45:47) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.15, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.9.4, Copyright (c) 2002-2020, by Derick Rethans

LARAVEL VERSION:

v7.11.0@f4563bd2e0875c59a1f7967abdbe5cef7f240117

BACKPACK VERSION:

4.1.4@4303aa07ec0c597abfcfe83896558ca6e98f0d6a

triage

Most helpful comment

It's the expected behaviour.

This is actually a question of "what is the default value of the repeatable input". Please note that the input value of repeatable will always be string as was intended to be used with json_decode.

Now, if you create a repeatable, leave it untouched and submit, it will give you a json string, and decode it it'll show something like:

array:1 [
    0 => array:3 [
        "name" => "",
        "email" => "",
        "mobile" => "",
    ]
]

If you click on the cross and delete the default element, you know that under the hood the array is removing one of its associating child element. In our case, it removes array[0], and the remaining is an empty array.

In such situation, __repeatable field return '[]' string after deleting all entries__ is an expected behaviour. AFAIK it is intact with other backpack input element concerning json.

If you think such behaviour gives you some troubles, you can illustrate an example situation, perhaps it worths further discussion.

All 4 comments

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps _a lot_ in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (_How do I do X_) - Gitter Chatroom;
  • Long questions (_I have done X and Y and it won't do Z wtf_) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome _awesome_ community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

It's the expected behaviour.

This is actually a question of "what is the default value of the repeatable input". Please note that the input value of repeatable will always be string as was intended to be used with json_decode.

Now, if you create a repeatable, leave it untouched and submit, it will give you a json string, and decode it it'll show something like:

array:1 [
    0 => array:3 [
        "name" => "",
        "email" => "",
        "mobile" => "",
    ]
]

If you click on the cross and delete the default element, you know that under the hood the array is removing one of its associating child element. In our case, it removes array[0], and the remaining is an empty array.

In such situation, __repeatable field return '[]' string after deleting all entries__ is an expected behaviour. AFAIK it is intact with other backpack input element concerning json.

If you think such behaviour gives you some troubles, you can illustrate an example situation, perhaps it worths further discussion.

It makes totally sense.

I had a default null value in the repeatable column entries because i added that column in an existent table.

I am going to close the issue.

Thanks a lot.

Wow - thanks a lot for the detailed explanation @justinmoh - I couldn't explain it so clearly even if I tried. Good job!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikael1000 picture mikael1000  路  3Comments

sonoftheweb picture sonoftheweb  路  3Comments

AlexanderWM picture AlexanderWM  路  3Comments

jorgepires picture jorgepires  路  3Comments

alexgmin picture alexgmin  路  3Comments