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

Add toggle for multiple select and removable tags #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaeltheshah
Copy link

This pull request addresses issue #100. It adds a boolean toggle named allowMultipleSelection that allows a user to select multiple tags at once.

let cities = ["London", "New York", "Chicago"]
let tagField = WSTagsField()
tagField.allowMultipleSelection = true

Also, a boolean toggle named removable is added that doesn't allow a tag to be removed. This is inside WSTagView and set with a setter named setRemovable(tags: [String], removable: Bool = false). This method will throw an exception if called before any tags are added.

let cities = ["London", "New York", "Chicago"]
let tagField = WSTagsField()
tagField.addTags(cities)
tagField.setRemovable(cities) //removable set to false by default

Finally, a helper function is created named getSelectedTagStrings() that gets all tags as a list of strings.

let cities = ["London", "New York", "Chicago"]
let tagField = WSTagsField()
tagField.getSelectedTagStrings()

simulator screen shot - iphone xr - 2019-01-05 at 22 06 19

@ricardopereira
Copy link
Member

@mochat97 Nice one, thank you. I'll test this and review it shortly. Exciting!

addTag(tag)
if let tagView = tagViews.last, autoSelectTagWhenAdded {
//There's a bug that causes the text to be truncated during animation ("New York" becomes "New Y..."). This delays animating the TagView until after it's set in the TextField.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think we should do another approach. This could not always solve the problem.

@@ -401,6 +416,15 @@ open class WSTagsField: UIScrollView {
repositionViews()
}

open func setRemovable(tags: [String], removable: Bool = false) {
assert(tagViews.count > 0, "There are no tagViews. Did you call this method after adding tags?")
Copy link
Member

Choose a reason for hiding this comment

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

Please try to find another way avoiding the use of asserts. This is quite unsafe in runtime.

@@ -13,19 +13,19 @@ protocol BackspaceDetectingTextFieldDelegate: UITextFieldDelegate {
func textFieldDidDeleteBackwards(_ textField: UITextField)
}

class BackspaceDetectingTextField: UITextField {
open class BackspaceDetectingTextField: UITextField {
Copy link
Member

Choose a reason for hiding this comment

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

This should not be open, we don't want to expose this to lib users.

@ricardopereira
Copy link
Member

Please provide a functional code in the Example app. Thank you for your contribution.

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