Skip to content

added maxItems option#257

Closed
jamestwebber wants to merge 10 commits intolukasoppermann:masterfrom
jamestwebber:maxitems
Closed

added maxItems option#257
jamestwebber wants to merge 10 commits intolukasoppermann:masterfrom
jamestwebber:maxitems

Conversation

@jamestwebber
Copy link
Copy Markdown
Contributor

Here is the PR for maxItems (alone). I didn't write a test for this, I am not sure where the best place to put it would be. There are currently no explicit tests of connectWith that I could see, and that would be the starting point.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.1%) to 91.743% when pulling 0d1d30d on jamestwebber:maxitems into 569970a on lukasoppermann:master.

@lukasoppermann
Copy link
Copy Markdown
Owner

Hey @jamestwebber, thank you very much, I will have a look at it now.

Are you saying you would need a connected test to know how to do it, or are you just not sure where to put it? If its the location, just create a new file: connectedSortable.js in the test folder. Also please try to not use jQuery, as mentioned in the other ticket we are removing it from the test.

Also can you please to the following for me:

  • rebase to master
  • remove all commits from your other PR in this one (use git rebase -i HEAD~N where N is the number of commits you added) now you can drop commits by replacing the pick with a drop (sorry, if you know this already, just making sure)
  • please remove all files but src/html.sortable.js from the PR
  • please adjust the Readme.md to mention your new feature and how it can be used

Thanks. 👍

if (!dragging || !_listsConnected(sortableElement, dragging.parentElement) || _data(sortableElement, '_disabled') === 'true') {
return
}
if (maxItems && _filter(_getChildren(sortableElement), _data(sortableElement, 'items')).length >= maxItems) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do ....length - 1 otherwise if I set maxItems to 3, I can only add 2 items.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because of the placeholder class getting added. If you pass an "items" option that doesn't match the placeholder, it works correctly this way. I think that's better than having it always off-by-one which seems confusing.

}

// max items
if (options.maxItems && typeof options.maxItems === 'number') {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just remove this entire if block and use options.maxItemsin line 698? You could check for typeof number down there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I don't know if a type check is even necessary, just sort of emulating what I saw elsewhere. The type check probably isn't necessary at all, it will act weird if people give a weird parameter but that's on them.

@jamestwebber jamestwebber deleted the maxitems branch May 9, 2017 19:04
@jamestwebber
Copy link
Copy Markdown
Contributor Author

Uh, that probably wasn't the right thing to do...I have a branch called maxitems with the correct history and changes but it's no longer attached to this PR.

@lukasoppermann
Copy link
Copy Markdown
Owner

Hey @jamestwebber, no worries just create a new PR with the branch. (Or is there another issue I don't understand. )

@jamestwebber jamestwebber mentioned this pull request May 10, 2017
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

Successfully merging this pull request may close these issues.

3 participants