Adds duplicate check for sort

This commit is contained in:
AliasAlreadyTaken 2024-09-14 23:55:37 +02:00
parent bd4a515544
commit de8c26f4fe
2 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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()