FilePicker
An element which is designed to select one or more files
Create from source
func NewFilePicker(session Session, params Params) FilePicker
Create new file picker object and returns its interface
Create from resource
FilePicker {
id = filePicker,
accept = "jpg, png"
}
Interface description
Inherit methods, properties and events from View
Files() []FileInfo
Returns the list of selected files. If there are no files selected then an empty slice is returned (the result is always not nil)
LoadFile(file FileInfo, result func(FileInfo, []byte))
Loads the content of the selected file. This function is asynchronous. The "result" function will be called after loading the data.
Properties
"accept"
Set the list of allowed file extensions or MIME types
Constant: Accept
Types: string
, []string
Internal type is string
, other types converted to it during assignment
Conversion rules
string
- may contain single value of multiple separated by comma(,
)
[]string
- an array of acceptable file extensions or MIME types
Examples
FilePicker {
accept="jpeg,png",
}
FilePicker {
accept="image/jpeg,image/png",
}
picker := rui.NewFilePicker(session, rui.Params{
rui.Accept: "jpeg,png",
})
picker := rui.NewFilePicker(session, rui.Params{
rui.Accept: "image/jpeg,image/png",
})
"multiple"
Controls whether multiple files can be selected
Constant: Multiple
Types: bool
, int
, string
Values
bool | int | string | Description |
---|---|---|---|
true |
1 |
"true", "yes", "on", "1" | Several files can be selected |
false |
0 |
"false", "no", "off", "0" | Only one file can be selected |
Events
"file-selected-event"
Fired when user selects file(s)
Constant: FileSelectedEvent
General listener format:
func(picker rui.FilePicker, files []rui.FileInfo)
where: * picker - Interface of a file picker which generated this event * files - Array of description of selected files
Allowed listener formats:
func(picker rui.FilePicker)
func(files []rui.FileInfo)
func()
Related global functions
func FilePickerByID(rootView View, id string) FilePicker
Return a FilePicker
with id equal to the argument of the function or nil if there is no such View or View is not FilePicker
func GetFilePickerAccept(view View, subviewID ...string) []string
Returns sets the list of allowed file extensions or MIME types. If the second argument (subviewID) is not specified or is an empty string then a value from the first argument (view) is returned.
func GetFilePickerFiles(view View, subviewID ...string) []FileInfo
Returns the list of FilePicker
selected files If there are no files selected then an empty slice is returned (the result is always not nil) If the second argument (subviewID) is not specified or is an empty string then selected files of the first argument (view) is returned
func GetFileSelectedListeners(view View, subviewID ...string) []func(FilePicker, []FileInfo)
Returns the "file-selected-event" listener list. If there are no listeners then the empty list is returned. If the second argument (subviewID) is not specified or is an empty string then a value from the first argument (view) is returned.
func IsMultipleFilePicker(view View, subviewID ...string) bool
Returns "true" if multiple files can be selected in the FilePicker
, "false" otherwise. If the second argument (subviewID) is not specified or is an empty string then a value from the first argument (view) is returned.
func LoadFilePickerFile(view View, subviewID string, file FileInfo, result func(FileInfo, []byte))
Loads the content of the selected file. This function is asynchronous. The "result" function will be called after loading the data. If the second argument (subviewID) is "" then the file from the first argument (view) is loaded