Repeatable field return '[]' string after deleting all entries
See original GitHub issueBug 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 © 1997-2018 The PHP Group Zend Engine v3.3.15, Copyright © 1998-2018 Zend Technologies with Xdebug v2.9.4, Copyright © 2002-2020, by Derick Rethans
LARAVEL VERSION:
v7.11.0@f4563bd2e0875c59a1f7967abdbe5cef7f240117
BACKPACK VERSION:
4.1.4@4303aa07ec0c597abfcfe83896558ca6e98f0d6a
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
c# - Is there an easy way to return a string repeated X number ...
If you only intend to repeat the same character you can use the string constructor that accepts a char and the number of...
Read more >Create and run a delete query - Microsoft Support
Delete queries remove all the data in each field, including the key value that makes a record unique. Use an update query. To...
Read more >delete_row() - ACF
Deletes a row of data from an existing Repeater or Flexible Content field value. ... $selector (string) (Required) The field name or field...
Read more >Using expressions in your forms: a reference for all operators ...
For a field within a repeat group, calculates the sum of all values. ... when this calculate expression is within a repeat group,...
Read more >How to remove characters/text from string in Excel - Ablebits
Remove a character and return the result as a number. ... To delete everything after a given character, the generic formula is: LEFT(string...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@justinmoh @stevebeyatte thanks for your pacience waiting and circunventing this issue, this was due to the fact that repeatable was beeing “pre-parsed” in javascript and that led to un-expected behavior.
Just tried this out myself in 4.2 branch where we completely refactored repeatable to be like regular form fields submitting arrays instead of json, and I can confirm that in this new version, when the value is empty it will save
null
in the database.This version is due to be out in a few days!
Thanks for sticking with us!
Pedro
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 ofrepeatable
will always be string as was intended to be used withjson_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:
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.