http://loopj.com/jquery-tokeninput/
The code I am working with is from a jquery-tokeninput fork which allows multiple NEW tokens to be entered in the box (not just ones that already exist). The format of the string that it returns when they click submit is this:
16,42,'Subway',37,'McDonald\'s',734.
Those are ID numbers for the tokens that exist, and for ones that don’t exist it wraps them in ‘quotes’.
My question is how do I change my new_custom_tokens method to interpret whether they have entered a new token or not (check if its in quotes). Ultimately its going to check if their account is old enough to add new tags, and then I need to run Tag.new I assume (so it only saves it when their completely valid, including the resource validations)
EDIT: I also think i need some kind of validation that wont split things within quotes
resource.rb
def tag_tokens=(tokens)
self.tokens_list = tokens.split(",")
if new_custom_tokens?
custom_token_time_restriction
else
self.tag_ids = self.tokens_list
end
end
def new_custom_tokens?
if self.token_list ... #... not sure
end
def add_new_tag_time_restriction
# TODO: Check if they are anonymous or their account is newer than 7 days
end
If I understood you correctly, this should do the trick:
Basically it loops through the token_list array and returns true if any of the tokens have the ‘ character.