fix(defaults): type casting for user input

This commit is contained in:
Qingping Hou
2016-09-21 23:52:40 -07:00
parent 902403bf0a
commit ca21ab4be5
2 changed files with 13 additions and 10 deletions

View File

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