properly handle empty text entry fields (including transformations)

This commit is contained in:
kepler155c@gmail.com
2019-11-13 14:24:54 -07:00
parent 7e520744a2
commit 64ec8c82d3
13 changed files with 64 additions and 51 deletions

View File

@@ -276,7 +276,7 @@ function substitutionPage:eventHandler(event)
self.info:draw()
elseif event.type == 'text_change' then
local text = event.text
local text = event.text or ''
if #text == 0 then
self.grid.values = self.allItems
else

View File

@@ -33,6 +33,7 @@ local tab = UI.Tab {
shadowText = 'id',
width = 5,
limit = 3,
transform = 'number',
},
add = UI.Button {
x = 28, y = 3,
@@ -78,6 +79,9 @@ end
function tab:eventHandler(event)
if event.type == 'form_complete' then
if event.values.type == 'disk_drive' and not event.values.drive_id then
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
else
ccemux.detach(event.values.side)
ccemux.attach(event.values.side, event.values.type)
@@ -85,9 +89,9 @@ function tab:eventHandler(event)
config[event.values.side] = {
type = event.values.type
}
if event.values.type == 'disk_drive' and tonumber(event.values.drive_id) then
if event.values.type == 'disk_drive' then
config[event.values.side].args = {
id = tonumber(event.values.drive_id)
id = event.values.drive_id
}
end
Config.update('ccemux', config)
@@ -95,6 +99,7 @@ function tab:eventHandler(event)
self.grid:draw()
self:emit({ type = 'success_message', message = 'Attached' })
end
elseif event.type == 'choice_change' then
if event.element == self.form.ptype then

View File

@@ -39,7 +39,7 @@ function page:eventHandler(event)
Sound.play(event.selected.name)
elseif event.type == 'text_change' then
if #event.text == 0 then
if not event.text then
self.grid.values = sounds
else
self.grid.values = { }

View File

@@ -85,7 +85,7 @@ local function rewriteFiles(p)
end
function tab:eventHandler(event)
if event.type == 'add_path' then
if event.type == 'add_path' and self.entry.value then
table.insert(self.grid.values, {
value = self.entry.value,
})

View File

@@ -246,7 +246,7 @@ function page:eventHandler(event)
Config.update('miloRemote', context.state)
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
self.filter = event.text
self.filter = event.text or ''
if #self.filter == 0 then
self.filter = nil
end

View File

@@ -272,7 +272,7 @@ function page:eventHandler(event)
end
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
self.filter = event.text
self.filter = event.text or ''
if #self.filter == 0 then
self.filter = nil
end

View File

@@ -21,12 +21,12 @@ local manageTab = UI.Tab {
[2] = UI.TextEntry {
width = 7,
formLabel = 'Min', formKey = 'low', help = 'Craft if below min',
validate = 'numeric',
transform = 'number',
},
[3] = UI.TextEntry {
width = 7,
formLabel = 'Max', formKey = 'limit', help = 'Send to trash if above max',
validate = 'numeric',
transform = 'number',
},
[4] = UI.Checkbox {
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',

View File

@@ -21,7 +21,7 @@ local setup = UI.SlideOut {
help = 'ID for the server',
shadowText = 'Milo server ID',
limit = 6,
validate = 'numeric',
transform = 'number',
required = true,
},
[2] = UI.TextEntry {
@@ -29,7 +29,7 @@ local setup = UI.SlideOut {
help = 'Use a slot for sending to storage',
shadowText = 'Inventory slot #',
limit = 5,
validate = 'numeric',
transform = 'number',
required = false,
},
[3] = UI.Checkbox {

View File

@@ -15,14 +15,14 @@ local storageView = UI.WizardPage {
formLabel = 'Priority', formKey = 'priority',
help = 'Larger values get precedence',
limit = 4,
validate = 'numeric',
transform = 'number',
shadowText = 'Numeric priority',
},
[2] = UI.TextEntry {
formLabel = 'Refresh', formKey = 'refreshInterval',
shadowText = 'seconds between refresh',
limit = 4,
validate = 'numeric',
tranform = 'number',
help = 'Refresh periodically',
},
[3] = UI.TextArea {

View File

@@ -42,11 +42,15 @@ function tab:eventHandler(event)
config.enabled = not not event.checked
elseif event.type == 'update' then
if self.timeout.value then
config.timeout = self.timeout.value
Config.update('saver', config)
self:emit({ type = 'success_message', message = 'Settings updated' })
os.queueEvent('config_update', 'saver', config)
else
self:emit({ type = 'error_message', message = 'Invalid timeout' })
end
end
return UI.Tab.eventHandler(self, event)
end

View File

@@ -42,11 +42,15 @@ function tab:eventHandler(event)
config.enabled = not not event.checked
elseif event.type == 'update' then
if self.timeout.value then
config.timeout = self.timeout.value
Config.update('secure', config)
self:emit({ type = 'success_message', message = 'Settings updated' })
os.queueEvent('config_update', 'secure', config)
else
self:emit({ type = 'error_message', message = 'Invalid timeout' })
end
end
return UI.Tab.eventHandler(self, event)
end

View File

@@ -106,7 +106,7 @@ local passwordPage = UI.WizardPage {
}
local function makeAddress(text, isPrivateKey)
local privKey = text
local privKey = text or ''
if not isPrivateKey then
privKey = Krist.toKristWalletFormat(privKey)
end

View File

@@ -25,7 +25,7 @@ local shopTab = UI.Tab {
formLabel = 'Price', formKey = 'price',
help = 'Per item cost',
required = true,
validate = 'numeric',
transform = 'number',
},
[3] = UI.TextEntry {
limit = 64,