admin-page-framework icon indicating copy to clipboard operation
admin-page-framework copied to clipboard

Repeated section of length of zero

Open ssimo3lsuhsc opened this issue 8 years ago • 5 comments

Hello. My name is Stuart Simon. I am trying to write a plugin that adds a meta box that allows users to add files with descriptions to a post type. What I need is to allow my repeating group to have zero length. I cannot set any of the fields in my repeating group to be required because at least one record is always there. The key is that this is bad data design. I don't want meaningless records clogging my database. I want to use your plugin because it allows adding custom attributes to its fields. I don't remember if nested repeatables are supported, but I thought of plugins other than CMB2 that allow me to set field attributes directly. ## Type of issue

  • [ ] Bug report.
  • [x] Suggestion.

Prerequisites

  • [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate,
  • [x] The issue still exists against the latest dev branch.
  • [x] This is not a usage question (Those should be directed to the community).
  • [ ] I have attempted to find the simplest possible steps to reproduce the issue.

Steps to reproduce the issue (for Bug report)

Expected behavior and actual behavior

When I follow those steps, I see...

I was expecting...

Environment

Browsers

  • [ ] Google Chrome
  • [ ] Mozilla Firefox
  • [ ] Internet Explorer

Operating System

  • [ ] Windows
  • [ ] Mac OS X
  • [ ] Linux
  • [ ] Mobile

Versions

  • Admin Page Framework version:
  • WordPress version:
  • PHP version:

Isolating the problem

  • [ ] This bug happens on the demo page.
  • [ ] The bug happens consistently across all tested browsers.
  • [ ] This bug happens with clean install (with the default theme and no plugin except the problematic one).

ssimo3lsuhsc avatar Feb 14 '17 06:02 ssimo3lsuhsc

Hi Stuart,

What I need is to allow my repeating group to have zero length.

I don't understand this part. Can you elaborate?

michaeluno avatar Feb 20 '17 01:02 michaeluno

Currently, every repeating group must have at least one row. If there is only one row, the “Remove Row” (or “Remove Item”) button is disabled. There are cases where this behavior is desirable: for instance, an ordering system should make sure there is at least one line item in every order. However, there are also many more cases where it is quite legitimate for a group to have zero rows. Consider attaching files. I want the user to be able to attach one or more files to a post. But for each one I should also require them to describe the file’s relation to the post. I need to be able to legitimately post

Attachments = []

Not

Attachments = [ “file” => “”, “description” => “” ]

And I can NOT mark either “file” or “description” as required, as the validation would fail when the user (with role of “contributor”) actually had no attachments to post. And remember, when writing your answer: The description should NOT be forced to match what it might be in the WP media database. A file can have different relationships to different posts and therefore different “description” values in different posts. Thank you!

Stuart Simon Graphics Specialist LSU Human Development Center 411 S Prieur St New Orleans, LA 70112 http://www.hdc.lsuhsc.edu/

From: Michael Uno [mailto:[email protected]] Sent: Sunday, February 19, 2017 7:19 PM To: michaeluno/admin-page-framework [email protected] Cc: Simon, Stuart A. [email protected]; Author [email protected] Subject: Re: [michaeluno/admin-page-framework] Repeated section of length of zero (#266)

EXTERNAL EMAIL: EVALUATE

Hi Stuart,

What I need is to allow my repeating group to have zero length.

I don't understand this part. Can you elaborate?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/michaeluno/admin-page-framework/issues/266#issuecomment-280966491, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATRYOHMUDzA3byP8niUNTyw1u6YgvR2dks5reOocgaJpZM4MAG8E.

ssimo3lsuhsc avatar Feb 20 '17 18:02 ssimo3lsuhsc

I thought I should be more succinct.

A repeating group named "group1" has two child fields, "field1" and "field2." When saved to the database, the data represented by the entries in the repeating group will be serialized thus:

$_POST['group1'] = array( 0 => array( 'field1' => 'foo', 'field2' => 'bar' ), 1 => array( 'field1' => 'Lorem' 'field2' => 'ipsum' ) ... )

In other words, the repeating group is always bound to a non-associative array in the data. What I am asking for is the special case that the repeater is bound to an empty array. The repeater in this case should have zero entries (where an "entry" may be called a "group" or "row" ). In my mind, all that is needed in the repeated group's DIV in that case should be the button that adds an entry.

What I can do is to show you how those of your competitors have handled the special case of a repeating field with zero entries.

Sent from my iPhone

On Feb 19, 2017, at 7:19 PM, Michael Uno <[email protected]mailto:[email protected]> wrote:

EXTERNAL EMAIL: EVALUATE

Hi Stuart,

What I need is to allow my repeating group to have zero length.

I don't understand this part. Can you elaborate?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/michaeluno/admin-page-framework/issues/266#issuecomment-280966491, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATRYOHMUDzA3byP8niUNTyw1u6YgvR2dks5reOocgaJpZM4MAG8E.

ssimo3lsuhsc avatar Feb 21 '17 06:02 ssimo3lsuhsc

Michael: I can't believe you're as out of touch with Github and your e-mail as you seem to be. When I first posted this issue, I had already contacted you using http://admin-page-framework.michaeluno.jp/contact/order-new-features/ at least two weeks before. Search your inbox for [email protected]mailto:[email protected] and click the earliest message that comes up. Maybe it was too much for you to deal with at the time.

When I say zero-length repeater, I mean that I want a repeater with no items/rows. You could also say that it has no children, or that the repeater occurs zero times. I want my contributors to attach one or more files to my posts, and I want to make sure they provide descriptions of each one. Two fields: File and Description, both required. But most of the posts will have no need for attachments, and thus the section should not occur at all for most posts.

Of course I could create a related post type and add it as an optional association (the post type holding the repeater would then be the child). But I'm not the only one who will be using the admin pages for my custom post types. And some people, they really don't want to have to navigate away from the parent's post type to the child's.

Thank you!

Stuart Simon Graphics Specialist LSU Human Development Center 411 S Prieur St New Orleans, LA 70112 http://www.hdc.lsuhsc.edu/

From: Simon, Stuart A. Sent: Tuesday, February 21, 2017 12:34 AM To: michaeluno/admin-page-framework [email protected] Subject: Re: [michaeluno/admin-page-framework] Repeated section of length of zero (#266)

I thought I should be more succinct.

A repeating group named "group1" has two child fields, "field1" and "field2." When saved to the database, the data represented by the entries in the repeating group will be serialized thus:

$_POST['group1'] = array( 0 => array( 'field1' => 'foo', 'field2' => 'bar' ), 1 => array( 'field1' => 'Lorem' 'field2' => 'ipsum' ) ... )

In other words, the repeating group is always bound to a non-associative array in the data. What I am asking for is the special case that the repeater is bound to an empty array. The repeater in this case should have zero entries (where an "entry" may be called a "group" or "row" ). In my mind, all that is needed in the repeated group's DIV in that case should be the button that adds an entry.

What I can do is to show you how those of your competitors have handled the special case of a repeating field with zero entries.

Sent from my iPhone

On Feb 19, 2017, at 7:19 PM, Michael Uno <[email protected]mailto:[email protected]> wrote: EXTERNAL EMAIL: EVALUATE

Hi Stuart,

What I need is to allow my repeating group to have zero length.

I don't understand this part. Can you elaborate?

You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/michaeluno/admin-page-framework/issues/266#issuecomment-280966491, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATRYOHMUDzA3byP8niUNTyw1u6YgvR2dks5reOocgaJpZM4MAG8E.

ssimo3lsuhsc avatar Mar 07 '17 17:03 ssimo3lsuhsc

Hi Stuart,

Sorry for the late response.

It sounds like a good option to have. However, I cannot guarantee when it is implemented.

As for the email you sent via the contact form, indeed I have missed it. I'll respond to it in email.

michaeluno avatar Mar 08 '17 01:03 michaeluno