summaryrefslogtreecommitdiffstats
path: root/acf2/model/field.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acf2/model/field.lua')
-rw-r--r--acf2/model/field.lua14
1 files changed, 11 insertions, 3 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua
index 777a311..7a7595a 100644
--- a/acf2/model/field.lua
+++ b/acf2/model/field.lua
@@ -54,10 +54,16 @@ end
M.Field = class(M.Member)
function M.Field:init(params)
+ if not params then params = {} end
+ util.setdefault(params, 'editable', not params.compute)
+
super(self, M.Field):init(params)
if self.compute then self.addr = node.null_addr end
- if self.editable == nil then self.editable = not self.compute end
+
+ if type(self.editable) ~= 'function' then
+ function self.editable(context) return params.editable end
+ end
self.condition = M.conv_filter(self.condition)
@@ -93,7 +99,7 @@ function M.Field:meta(context)
local res = super(self, M.Field):meta(context)
res.type = self.dtype
- res.editable = self.editable
+ res.editable = self:editable(context)
res.condition = self.condition
res.required = self.required
res.default = self.default
@@ -156,7 +162,9 @@ function M.Field:normalize(context, value) return value end
function M.Field:validate(context, value) end
function M.Field:save(context, value)
- if not self.editable then raise(context.path, 'Is not editable') end
+ if not self:editable(context) then
+ raise(context.path, 'Is not editable')
+ end
self:_save(context, self:_validate(context, value))
end