quick_script 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module QuickScript
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -278,6 +278,26 @@
278
278
  self[field](val)
279
279
  if (typeof(field) == "string")
280
280
  self.fields.pushOnce(field)
281
+
282
+ ko.validate_for = (field, fn, msg, self) ->
283
+ self.validations = {} unless self.validations?
284
+ self.validations[field] = [] unless self.validations[field]?
285
+ self.validations[field].push {test : fn, msg : msg}
286
+ self[field].is_valid = ko.computed ->
287
+ valid = true
288
+ for val_obj in self.validations[field]
289
+ valid &&= val_obj.test(self[field]())
290
+ valid
291
+ , self unless self[field].is_valid?
292
+
293
+
294
+ ko.validate_fields = (fields, fn, self) ->
295
+ msgs = []
296
+ for field in fields
297
+ for val_obj in self.validations[field]
298
+ if !val_obj.test(self[field]())
299
+ msgs.push val_obj.msg
300
+ fn(msgs)
281
301
 
282
302
  ko.addSubModel = (field, model, self) ->
283
303
  if self[field]?
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 0
9
- version: 0.9.0
8
+ - 1
9
+ version: 0.9.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alan Graham
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-09-10 00:00:00 -04:00
17
+ date: 2012-09-18 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20