generated from your-land/yl_template
Adds duplicate check for sort
This commit is contained in:
parent
bd4a515544
commit
de8c26f4fe
6
api.lua
6
api.lua
@ -315,6 +315,11 @@ local function create_question(id, question, category, sort, allowed_types,
|
||||
"answers cannot be nil or empty if allowedtypes has either multiplechoice or singlechoice")
|
||||
end
|
||||
|
||||
-- Specialcase : given sort is a duplicate
|
||||
if ((type(sort) == "number") and (yl_survey.is_duplicate(record, sort) == true)) then
|
||||
return false, yl_survey.t("sort is duplicate")
|
||||
end
|
||||
|
||||
local record = yl_survey.get_record(id)
|
||||
|
||||
if (record == nil) then
|
||||
@ -359,3 +364,4 @@ function yl_survey.create_question(id, question, category, sort, allowed_types,
|
||||
answers, enabled)
|
||||
return create_question(id, question, category, sort, allowed_types, answers, enabled)
|
||||
end
|
||||
|
||||
|
||||
17
internal.lua
17
internal.lua
@ -127,6 +127,23 @@ function yl_survey.find_next_free_number(record, target)
|
||||
return find_next_free_number(record, target)
|
||||
end
|
||||
|
||||
-- yl_survey.is_duplicate(record, sort)
|
||||
|
||||
local function is_duplicate(record, sort)
|
||||
for key, question in pairs(record) do
|
||||
if (tonumber(key) ~= nil) then
|
||||
if (question[sort] == sort) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function yl_survey.is_duplicate(record, sort)
|
||||
return is_duplicate(record, sort)
|
||||
end
|
||||
|
||||
-- Load and save
|
||||
|
||||
local function get_savepath()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user