TypeRocket / core

TypeRocket core source files where all the magic lives.
https://typerocket.com
36 stars 21 forks source link

Way to not save repeater fields if empty? #103

Closed fredy31 closed 2 years ago

fredy31 commented 2 years ago

I've got a site with a huge repeater, with 20-30 fields in it, but most fields are not used on every lap through (Its basically text, product info, faq accordion, etc)

But thing is, when it saves it seems I've hit a limit at some point. There is too much information to save (the meta is about 40kb at the end of the 11th instance)

But a lot of that weight is empty fields saved like 'field':'' that are there every time. Would there be a way to quickly trim the fat by just putting in a condition that would make it that if the field is empty in the repeater, just don't put it in the serialized array?

kevindees commented 2 years ago

Hey @fredy31

This is a great question. I can think of two solutions.

  1. Save the data to a custom table so you can get the database field type to allow for more storage space. If this is a WP table data space issue.
  2. Try out the conditional fields mode in Pro.

Conditional fields with modes “display” and “include”… when using “include” it will remove the input fields name attribute when the condition is not met instead of hiding them with CSS only.

  1. This means you can use conditional to toggle field types and have those fields use the same field name in the UI without needing unique field names.
  2. You can use this to cause specific fields from being sent via post data to trim down the data sent over to be saved.

I need to add this information to the docs.

echo $form->toggle('Background');
echo $form->image('Image')->when('background', false)->conditionMode('include');
echo $form->background('Image')->when('background')->conditionMode('include');
fredy31 commented 2 years ago

Could there also be a thing where Typerocket would stop after like... 700 fields?

But yeah I should maybe ask my boss to push for Pro in this case.

kevindees commented 2 years ago

@fredy31

You can set a limit on the repeater field if you needed to limit the number of fields $repeater->setLimit(10);.

kevindees commented 2 years ago

@fredy31

Added this information to the docs.

https://typerocket.com/docs/v5/conditional-fields/#section-modes

Thanks, Kevin