Module ui.widget.inputdialog
Widget for taking user input.
Example:
local InputDialog = require("ui/widget/inputdialog") local UIManager = require("ui/uimanager") local logger = require("logger") local _ = require("gettext") local sample_input sample_input = InputDialog:new{ title = _("Dialog title"), input = "default value", -- A placeholder text shown in the text box. input_hint = _("Hint text"), -- input_type = nil, -- default for text -- A description shown above the input. description = _("Some more description."), -- text_type = "password", buttons = { { { text = _("Cancel"), id = "close", callback = function() UIManager:close(sample_input) end, }, { text = _("Save"), -- button with is_enter_default set to true will be -- triggered after user press the enter key from keyboard is_enter_default = true, callback = function() logger.dbg("Got user input as raw text:", sample_input:getInputText()) logger.dbg("Got user input as value:", sample_input:getInputValue()) end, }, } }, } UIManager:show(sample_input) sample_input:onShowKeyboard()
To get a full screen text editor, use:
fullscreen = true, -- No need to provide any height and width. condensed = true, allow_newline = true, cursor_at_end = false, -- and one of these: add_scroll_buttons = true, add_nav_bar = true,
To add |Save|Close| buttons, use:
save_callback = function(content, closing) -- ...Deal with the edited content... if closing then UIManager:nextTick( -- Stuff to do when InputDialog is closed, if anything. ) end return nil -- sucess, default notification shown return true, success_notif_text return false, error_infomsg_text end
To additionally add a Reset button and have |Reset|Save|Close|, use:
reset_callback = function() return original_content -- success return original_content, success_notif_text return nil, error_infomsg_text end
If you don't need more buttons than these, use these options for consistency between dialogs, and don't provide any buttons. Text used on these buttons and their messages and notifications can be changed by providing alternative text with these additional options:
reset_button_text save_button_text close_button_text close_unsaved_confirm_text close_cancel_button_text close_discard_button_text close_save_button_text close_discarded_notif_text
If it would take the user more than half a minute to recover from a mistake, a "Cancel" button must be added to the dialog. The cancellation button should be kept on the left and the button executing the action on the right.
It is strongly recommended to use a text describing the action to be executed, as demonstrated in the example above. If the resulting phrase would be longer than three words it should just read "OK".