Maybe it's interesting to collapse the fields by default, at least in the case that the developer has defined a custom header template (#27). The idea is to hide clutter to make it cleaner for the user.
Somewhat related to #41 (add collapse all button).
Edit: changed issue title, it would be better to just add a flag as mentioned by @m1r0 instead of assuming that if there is a template the field should collapse.
This would be perfect for what I need.
Currently I have a complex field set up on pages where a user will commonly create 10+ rows containing 4 or 5 fields each - makes for lots of scrolling. Collapsing by default would make the screen a lot more readable.
I've just made this little script to handle this situation:
function cf_collapse_complex_fields($field) {
add_action('in_admin_footer', function () use ($field) {
?>
<script type="text/javascript">
jQuery(function () {
var counter = 0; // Tries counter
var tries = 10;
var delay = 250;
var query = '#carbon-_<?php echo $field; ?>-complex-container .carbon-btn-collapse';
function check() {
var els = jQuery(query);
if (els.length) {
els.click();
} else if (counter < tries) {
counter++;
setTimeout(check, delay);
}
}
check();
});
</script>
<?php
});
}
// Somewhere else
// `program` is the name of the complex field to collapse
cf_collapse_complex_fields('program');
Nice idea! We will consider adding a collapsed flag option to the complex field in a future version.
I'm working on this, trying to understand how CF works… I was thinking in something like this:
collapse() method in phpBut maybe, you prefer to keep it opened both when creating and duplicating?
@doup, yeah, keeping the group open in both situations maybe makes more sense. We may change this depending on how it feels in practice.
This feature was added as set_collapsed(). Thanks @doup for the implementation! 👍
Most helpful comment
Nice idea! We will consider adding a
collapsedflag option to the complex field in a future version.