Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't remove all items in repeatable group #312

Closed
ashleykolodziej opened this issue May 5, 2015 · 14 comments
Closed

Can't remove all items in repeatable group #312

ashleykolodziej opened this issue May 5, 2015 · 14 comments

Comments

@ashleykolodziej
Copy link

I have a repeatable group set up, and after adding a number of items, I can't delete the last remaining item. After I delete the second to last item, the remove buttons on the last item are disabled. Would it be possible to get an update to allow deleting all items?

I'm using the latest public version, but noticed the trunk version's remove function only checks for # of groups > 1 in the JS as well. https://github.com/WebDevStudios/CMB2/blob/trunk/js/cmb2.js#L552

@jtsternberg
Copy link
Member

If you delete all the fields, there is no way to add your data. If you want to reset, I suggest adding an empty field, and deleting all others.

@jtsternberg
Copy link
Member

Closing for now.

@ashleykolodziej
Copy link
Author

You should be able to add a group field back in if you need it again, though, right? When you first open up a page, you don't have a repeatable field by default - you have to add it. It makes sense that if you delete all fields, this is the state you go back to. From a client standpoint, it's unintuitive to have to add to delete. That's something I can explain to them, though.

The only problem I'm having with this - if I mark a field as required in the attributes, I can't save the page without filling that field out - so I can't save the page with an empty callout. I could just check if certain things are empty when I display my callout, but I'd prefer to use the required attribute so it's really clear to the user if something I need is missing.

This is how I have the fields set up - Footer Callout is my repeatable group that I'd like to be able to delete. When I go to save it, the callout title field is required, so I can't save the page with this blank callout to reset. Any ideas?

screen shot 2015-05-07 at 11 40 08 am

@jtsternberg jtsternberg reopened this May 7, 2015
@jtsternberg
Copy link
Member

Hmm, that's an interesting situation. Re: your first question, how do you envision it working? the space being empty w/ only an 'add' button after they remove the last item? Or that the last items field values get removed? I guess I'm not positive I understand what you're looking for. From a UX standpoint, I feel like removing all the fields is not intuitive either (I agree that adding to remove is also not intuitive).

Re: second question, you'd probably have to do some jQuery on submit magic to check if it's a blank group and if so, remove the 'required' attribute.

@ashleykolodziej
Copy link
Author

Wow - I was convinced you started out with no fields to fill in, but you're right, there is at least one repeatable field from the start, even when you make a new page. My bad. :)

I'd imagine it being empty with an "add" button, like below - for the way I'm using it, it makes sense to me to be able to add/delete everything, since I'm using them to control chunks of optional content on a page. On the one hand, I like that you see what information you need right away, from the beginning - but I guess it threw me off to be able to delete everything without a problem and then hit a wall with the last one. That makes me think that there needs to be at least one callout, which isn't the case with the content type I'm building with this - I know there are situations in my site where no footer callouts are needed at all. Maybe there could be an option to allow an empty state? I think if it starts as empty, you add callouts, you delete all of them, and it goes back to being empty, that makes sense for content that is completely optional - and it's reassuring to me that I know it won't show up on my page if I save it, because it's not there.

Either way, I'll look into the jQuery on submit magic. Thanks for your help!

screen shot 2015-05-08 at 9 55 21 am

@ashleyfae
Copy link

This is something I'd like to see too. Maybe a nice solution would be:

If they try to remove the last item, simply empty all fields so they have no values and then hide the container. So it's technically still there, but just hidden to the user?

@jtsternberg
Copy link
Member

@nosegraze I don't think that's a bad solution, though there may be some issues that arise from that as well. For instance, If you have a radio input with 3 values, then hide the container, that value will still get set in the DB, and the user will not understand why. When the UI is visible, it's clear what happened.

@modemlooper
Copy link

https://buddypress.trac.wordpress.org/browser/trunk/src/bp-xprofile/bp-xprofile-admin.php

BuddyPress has admin page to handle profile field groups and fields. Might be worth looking through

@bentalgad
Copy link

I think this is really a "must"! it's so inconvenient to have useless empty fields and to have to add one to delete one.

@jtsternberg
Copy link
Member

Ok, I've made some improvements. For reasons mentioned above, I'm not a fan of hiding the group/row without a better UX for it, but now when you click "remove" on the last item, it resets it to blank values.

@bentalgad
Copy link

Thanks, great. but i still think it should be completely empty. having just the "add" button. also when programmatically add group field i think right now it would add another one and not replace the empty one.

@fu-raz
Copy link

fu-raz commented Sep 22, 2017

Wow this looks like a really old issue, but was revived recently?

Is there an official version where this feature is added? Or do I have to pull master for this? Also I was wondering if there's a way to define the number of items that get added to the UI.
Something like:

$cmb->add_field([
'name' => 'The group',
'id' => 'prefix_group_id',
'type' => 'group',
'options' => [
'group_title' => __('Title'),
'add_button' => __('Add item'),
'remove_button' => __('Remove item'),
'sortable' => true,
'closed' => false,
'open_ui_items' => 3
]
]);

But with a better name than 'open_ui_items' and also 0 being an option (getting on topic again).

@tw2113
Copy link
Contributor

tw2113 commented Sep 22, 2017

Trunk would have all the latest features and such. Master is more akin to the "release version".

@tw2113
Copy link
Contributor

tw2113 commented Sep 22, 2017

Regarding the open ui items bit, if you could create a new enhancement issue for that, we'd appreciate it. It'll get lost being tacked on to this issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants