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

Allow to limit the quantity of nested items #194

Closed
sobrinho opened this issue Feb 1, 2014 · 2 comments
Closed

Allow to limit the quantity of nested items #194

sobrinho opened this issue Feb 1, 2014 · 2 comments

Comments

@sobrinho
Copy link

sobrinho commented Feb 1, 2014

Hey,

What do you think about an option to limit the quantity of nested items?

Rails already support that and throws an exception when you exceed, i.e.:

accepts_nested_attributes_for :things, limit: 3

It means you only can have at most 3 things, otherwise, an exception is thrown.

Would be great to have a option to work with that, i.e.:

link_to_add_association 'Add', f, :things, limit: 3

In that case, if the user hit the 3 limit, the add button just stop to work and came back to work if him remove at least 1 thing.

Also, we'll need a custom event after adding the last item to handle the interface (alerts, classes, etc), i.e.:

$('#container').on('cocoon:limit-reached', function (e) {
  $(".add-thing").addClass("disabled");
});

Makes sense? Would you allow pull request implementing this?

@nathanvda
Copy link
Owner

This request has popped up a few times, and my standard response would be something like i mentioned in #176 (also see #59).

However your approach sounds interesting.

The harder part: imho if a button is not allowed to be pressed, just hide it (a disabled button mostly just confuses/annoys people). But that is a personal taste/rule.

But I would definitely consider such a pull request.

@sobrinho
Copy link
Author

#206 seems the way to go, closing :)

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

No branches or pull requests

2 participants