Skip to content

Instantly share code, notes, and snippets.

@sinslav
Created April 19, 2016 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinslav/4cd01ee1cc4c22c0eb5f85c0aa36459f to your computer and use it in GitHub Desktop.
Save sinslav/4cd01ee1cc4c22c0eb5f85c0aa36459f to your computer and use it in GitHub Desktop.
backbone file validation
File = Backbone.Model.extend
validate: (args) ->
result
if !@collection.isUniqueFile(args)
result = 'File already in list'
result
Files = Backbone.Collection.extend
model: File
isUniqueFile: (file) ->
found
for f in @models
if f.get('name') is file.name
found = f
break
if found
false
else
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment