question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 © 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pxpmcommented, Dec 16, 2021

@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

3reactions
justinmohcommented, May 20, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found