apostrophe icon indicating copy to clipboard operation
apostrophe copied to clipboard

aposSingletonIsEmpty doesn't work as expected

Open dannyblv opened this issue 12 years ago • 6 comments

Hey,

seems like aposSingletonIsEmpty works when there isn't items inserted yet, but when I insert an item and remove it (and it gets empty again) it doesn't work anymore(like its not empty). Im using it for schema-widgets I've created.

any ideas? thanks!

dannyblv avatar Aug 10 '14 12:08 dannyblv

I can confirm this one. It can be easily reproduced by creating a schema widget with an array of slideshows for instance.

For some reason, even if you delete all the slideshows via the UX, there is always a "leftover" last entry with an empty items array that would make aposSingletonIsEmpty believe it isn't empty.

etodanik avatar Aug 27 '14 00:08 etodanik

Thanks guys, sorry for the delay- we're going to take a look at this on Friday.

kylestetz avatar Aug 27 '14 11:08 kylestetz

Hey all, We've improved aposSingletonIsEmpty to handle the new singleton syntax today, but detecting empty schema-widgets will take another effort. Since we need to be mindful of default values and other possibilities with each content type, we're going to work on building a comprehensive 'empty' method for schema-widgets. Until then, we'll leave this issue open.

mcoppola avatar Aug 29 '14 19:08 mcoppola

Cool! Is the current iteration addressing the problem I described where if you add some stuff to the array and then remove all of them, an empty ghost-entry still exists and messes with aposSingletonIsEmpty?

etodanik avatar Aug 29 '14 19:08 etodanik

Danny, the current iteration should handle that ghost-entry, but not yet for schema-widgets.

By the way:

Old Syntax aposSingletonIsEmpty( { area: page.image1, type: 'slideshow' } )

New Syntax aposSingletonIsEmpty( page, 'image1', 'slideshow' )

mcoppola avatar Aug 29 '14 19:08 mcoppola

This works for schema widgets now.

In particular, a schema field of the "array" type with no entries in it is considered empty.

All schema field types have a reasonable definition of empty. Note that matching your default value (the "def" property) does NOT make something empty, because sometimes people intentionally set defaults that no one would consider empty. Emptiness for a string is an empty string, etc.

You can provide an "empty" function when defining a custom schema field type.

boutell avatar Sep 02 '14 16:09 boutell