goldnead / statamic-collapse-fieldtype

A Collapse-Fieldtype for Statamic to beautifully hide and show your fields.
MIT License
2 stars 3 forks source link

Fields are not cleared/removed when empty #2

Open Sennik opened 1 year ago

Sennik commented 1 year ago

Love this initiative!

One issue though. When I config the fields within the 'collapse fieldtype' as clearable they are not removed after I cleared them.

Normal behavior is that fields with no value in them are cleared from the content Yaml file (When 'allways save' is off which is the default).

Now my empty 'images' have {} and my 'select fields' have 'null' instead of them disappearing all the way.

To complete my information, my fields are added from a existing fieldset and one or two solo fields (mostly selects)

Additional question/wish:

Fields within the collapsed field are now grouped within that field. This could be an issue when using the 'Collapsed field' as an 'upgrade' on existing content (templates have to be updated too). An option to leave them ungrouped at the base level would be nice.

Keep up the good work!

pssssst: a tabbed interface would be nice too!

goldnead commented 1 year ago

Hey @Sennik Thanks for opening this issue. As I remember, in one of the recent versions, Statamic introduced the feature "always save". I presume this has to do with the issue you're experiencing, as I remember the addon removing cleared fields correctly in the past. I'll have a look into this.

You are right that fields are grouped within the collapse fieldtype. The reason for this is, that it acts "in disguise" as a structured content field like a replicator or a grid fieldtype. Trying to bring the data into root level seems to come with a few validation problems as well as the need to heavily rewrite the addon. But it was a few years ago I released the addon so i might look into this as well with fresh eyes 👀 .

I love the idea of a tabbed interface. Do you have a special use-case in mind? Would you be open to open a feature request with a few details to this?

Thanks

Sennik commented 1 year ago

Hi @goldnead

Thanks for your response. It is a very usefull add-on so I hope you will be able tp update it so it removes empty fields from the Yaml file.

Tabbed interface I tend to create extensive Set's to use in my Bard or Replicator fields. Normally I make these Bard or Replicator fields as a fieldset so I can use it in all collections I desire. This way I can make beautiful pages with a couple of sets per page.

These set's are getting quiet extensive sometimes, especially when using grids (or alike) but also because I am using several fields for (optional) styling choices in every set (also a reusable fieldset). So for example, a set can contain fields for main content like title, content and one or more images, a grid with multiple items and or images and a section with styling and markup selections. And important: almost all of these things are optional. The front-end checks if a field exists before showing it's content (and markup). So sometimes only the title and text are relevant another time only the items, hence the wish to spread these fields over tabs.

I think it is more organized this way.

Is this example clear enough for you?