diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-12-17 16:56:43 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-12-17 19:28:56 +0200 |
commit | de10682ab7404168aa6086f2f3199841fd97ea2a (patch) | |
tree | 12150b274245df3316c8ce2a44f40c0280c65f82 /acf2/model/field.lua | |
parent | a8aa513b9d07e8cabdb541c5b01d51caf21673bb (diff) | |
download | aconf-de10682ab7404168aa6086f2f3199841fd97ea2a.tar.bz2 aconf-de10682ab7404168aa6086f2f3199841fd97ea2a.tar.xz |
model: range checking for number fields
Diffstat (limited to 'acf2/model/field.lua')
-rw-r--r-- | acf2/model/field.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua index 57c558f..4307f6f 100644 --- a/acf2/model/field.lua +++ b/acf2/model/field.lua @@ -227,6 +227,16 @@ function M.Number:normalize(context, value) return value and tonumber(value) or value end +function M.Number:validate(context, value) + super(self, M.Number):validate(context, value) + if self.min and value < self.min then + raise(context.path, 'Minimum value is '..self.min) + end + if self.max and value > self.max then + raise(context.path, 'Maximum value is '..self.max) + end +end + M.Integer = class(M.Number) |