Form
Form component for Universal Dashboard
Forms provide a way to collect data from users.
Forms can include any type of control you want. This allows you to customize the look and feel and use any input controls.
Data entered via the input controls will be sent back to the the OnSubmit
script block when the form is submitted. Within the OnSubmit
event handler, you will access to the $EventData
variable that will contain properties for each of the fields in the form.
For example, if you have two fields, you will have two properties on $EventData
.
Supported Controls
The following input controls automatically integrate with a form. The values that are set within these controls will be sent during validation and in the OnSubmit
event handler.
Simple Form
Simple forms can use inputs like text boxes and checkboxes.
Formatting a Form
Since forms can use any component, you can use standard formatting components within the form.
Returning Components
When a form is submitted, you can optionally return another component to replace the form on the page. You can return any Universal Dashboard component. All you need to do is ensure that the component is written to the pipeline within the OnSubmit
event handler.
Validating a Form
Form validation can be accomplished by using the OnValidate script block parameter.
Canceling a Form
You can define an -OnCancel
event handler to invoke when the cancel button is pressed. This can be used to take actions like close a modal.
Displaying output without Replacing the form
Although you can return components directly from a form, you may want to retain the form so users can input data again. To do so, you can use Set-UDElement
and a placeholder element that you can set the content to.
In this example, we have an empty form that, when submitted, will update the results
element with a UDCard.
Schema Forms
Instead of defining all the layout and logic for forms using cmdlets, you can also define a form based on a hashtable of schema. This version of forms is based on react-jsonschema-form.
Fields
You define fields that accept string, number, integer, enum and boolean types. This changes the type of input shown.
Required Properties
You can use the required
property to set a list of required properties.
Note that the properties need to be lower case! For example, you need to ensure the keys in your properties hashtable are lower case and the list of required properties are also lower case.
Ordering
You can use the schemaUI
property to modify the ordering of the fields.
Arrays
You can create forms that accept 0 to many objects. The user will be able to add and remove objects to the form.
Script Forms
You can automatically generate forms based on scripts in your PowerShell Universal environment. Script forms will generate input components based on the param
block. Script forms automatically support progress and feedback.
Script forms also support displaying the output as text or a table.
API
Last updated