Website.set_data_validation#
- Website.set_data_validation(func)[source]#
Validate data received from JavaScript before using it.
ToUI receives data from JavaScript in the form of a JSON object. To validate this data before allowing ToUI to use it, input a function that checks the data. This function should have one argument data and should either return
TrueorFalse. If the function returnsFalse, the data will not be used by ToUI.Currently, there are two types of JSON objects that ToUI receives. One of the JSON objects contains the following keys:
- {type: ‘page’,
func: …, args: …, url: …, html: …}
type is the type of JSON object, and it always has the value ‘page’ when JavaScript sends the HTML document as data. func contains the name of the Python function that should be called, args are the arguments of this function, url is the URL of the HTML page that sent the data, ‘html’ is the HTML document itself as a string.
Another type of JSON object is a JSON that contains uploaded files:
- {type: ‘files’,
files: …}
You can get the uploaded files using the method Element.get_files().
However, note that the structures of the JSON objects might change in future versions of ToUI.
- Parameters:
func (Callable) – A function that validates data received from JavaScript. It should have one argument data and should either return
TrueorFalse.
See also