Some functionalities for input dialogs.
Live input custom-check with a boolean function
Adding a 'check' property to entries, a function taking in parameter the value and returning boolean of value validity.
function lockerNumberCheck(value)
return string.len(value) == 4 and tonumber([value](s:sub(1, 1))) == nil
end
local input = lib.inputDialog('Identité', {
{ type = "input", label = "Locker ID", placeholder = "A000", check = lockerNumberCheck},
})
On field value change, call the function and, if invalid, change the background color of the field to a red bg color, and block the 'Confirm' button.
min/max for number inputs too
Adding a 'min' and 'max' property, like on sliders, to number type entries, upon leaving focus on field or after using increment / decrement arrow, if it's < min, set value to min, if it's >max set value to max.
local input = lib.inputDialog('Gentleness test', {
{ type = "number", label = "Number counter", default = 12 }
})
Pre-filled values
Adding a 'value' property to entries to define a pre-filled value. Useful when editing old values for example.
local input = lib.inputDialog('Gentleness test', {
{ type = "input", label = "Locker ID", placeholder = "A000", value = "B158" },
{ type = 'select', label = 'Cutest animal', value = 'meow_hater', options = {
{ value = 'kittens', label = 'Kittens' },
{ value = 'cats', label = 'Cats' },
{ value = 'meow_hater', label = 'I\'m idiot i don't like cats'},
}}
})
Date input type
Adding a 'date' input type when you need date input (i.e. character creation) :D
Sub functionalities :
Max / min date like on sliders too
local input = lib.inputDialog('Gentleness test', {
{ type = "date", label = "Date of birth", value = "B158" },
})
Required fields
Adding a 'required' optional boolean attribute to all inputs, blocking the 'Confirm' button if it's empty (and add a * need the field name ?)
local input = lib.inputDialog('Gentleness test', {
{ type = "date", label = "Date of birth", required = true },
})
Cancel button toggling
Adding an option for disabling option to leave menu without pressing 'Confirm', useful on menu that shouldn't be left unanswered like character creation eventually or stuff like this
I dont really know how to implement it tho
maybe a third optional argument as an object called 'options' for non field-related options
lib.inputDialog(heading, rows, options)
local input = lib.inputDialog('Gentleness test', {
{ type = "date", label = "Date of birth", value = "B158" },
},
{
canCancel = false
})
Layout types
A separator entry
Adding a separator entry type giving no result or nil and that can either be a white-space or an horizontal line
Default as horizontal line.
local input = lib.inputDialog('New history entry', {
{ type = "input", label = "Name" },
{ type = "number", label = "Price " },
{ type = "separator"}, -- separator line
{ type = "number", label = "Buying price", placeholder = "leave empty if it was a gift" },
{ type = "separator", content = "white-space" }, -- whitespace
{ type = "number", label = "Selling price" },
{ type = "separator", content = "default" }, -- separator line
})
A label entry
Adding a label entry type showing a text to give additional info to user.
local input = lib.inputDialog('Model info', {
{ type = "input", label = "Name" },
{ type = "label", value = "Public info :" },
{ type = "number", label = "Buying price" },
{ type = "number", label = "Selling price" },
{ type = "number", label = "Buying commission" },
{ type = "number", label = "Selling commission" },
{ type = "label", value = "Note : this will remove sales of this model from history" },
})