mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
fix(defaults): type casting for user input
This commit is contained in:
@@ -209,14 +209,7 @@ function SetDefaults:init()
|
||||
is_enter_default = true,
|
||||
enabled = true,
|
||||
callback = function()
|
||||
local new_value = self.set_dialog:getInputText()
|
||||
if setting_type == "boolean" then
|
||||
if new_value == "true" then
|
||||
new_value = true
|
||||
else
|
||||
new_value = false
|
||||
end
|
||||
end
|
||||
local new_value = self.set_dialog:getInputValue()
|
||||
if _G[setting_name] ~= new_value then
|
||||
_G[setting_name] = new_value
|
||||
self.defaults_value[i] = new_value
|
||||
|
||||
@@ -10,7 +10,7 @@ Example:
|
||||
title = _("Dialog title"),
|
||||
input = "default value",
|
||||
input_hint = "hint text",
|
||||
input_type = "text",
|
||||
input_type = "string",
|
||||
-- text_type = "password",
|
||||
buttons = {
|
||||
{
|
||||
@@ -26,7 +26,8 @@ Example:
|
||||
-- triggered after user press the enter key from keyboard
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
print('Got user input:', sample_input:getInputText())
|
||||
print('Got user input as raw text:', sample_input:getInputText())
|
||||
print('Got user input as value:', sample_input:getInputValue())
|
||||
end,
|
||||
},
|
||||
}
|
||||
@@ -177,6 +178,15 @@ function InputDialog:getInputText()
|
||||
return self._input_widget:getText()
|
||||
end
|
||||
|
||||
function InputDialog:getInputValue()
|
||||
local text = self:getInputText()
|
||||
if self.input_type == "number" then
|
||||
return tonumber(text)
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
|
||||
function InputDialog:setInputText(text)
|
||||
self._input_widget:setText(text)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user