Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 72 additions & 2 deletions docs/Getting-Started/Migrating/08-to-10.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,81 @@ To assist with most migrations there is a helper function: `ConvertTo-PodeWebOpt

```powershell
New-PodeWebSelect -Name 'Example' -Options @(
@('Option1', 'Option2') | ConvertTo-PodeWebOption -SelectedOption 'Option1'
'Option1', 'Option2' | ConvertTo-PodeWebOption -SelectedOption 'Option1'
)
```

The `Update-PodeWebSelect` action sees the same update as well. Additionally the `-Value` on `Set-PodeWebSelect` is now `-OptionName`.
The `Update-PodeWebSelect` action sees the same update as well.

Additionally `Set-PodeWebSelect` is now `Select-PodeWebSelectOption`, and the `-Value` parameter is now `-OptionName`.

Furthermore, new Actions have been created to Add and Remove Select options; and a new Datalist element has been created as well.

### Checkboxes

Checkboxes have seen a similar update to Selects; originally you would create a Checkbox via `New-PodeWebCheckbox` and supply `-Options` as a string array, and optionally `-DisplayOptions`.

Now, you can create Options via the new `New-PodeWebOption` function. The `-Options` on `New-PodeWebCheckbox` now accepts an array of these elements, and the `-DisplayOptions` parameter has moved to `New-PodeWebOption` as `-DisplayName`. Additionally, while an Alias does exist, `-Checked` has been renamed to `-Selected`.

For example, the following previous Checkbox element:

```powershell
New-PodeWebCheckbox -Name 'Example' -Options @('Option1', 'Option2')
```

Would now be the following instead:

```powershell
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1' -Selected
New-PodeWebOption -Name 'Option2'
)
```

To assist with most migrations there is a helper function: `ConvertTo-PodeWebOption`. You can pipe an original raw string array into this, and it will convert to strings into Option elements for you:

```powershell
New-PodeWebCheckbox -Name 'Example' -Options @(
'Option1', 'Option2' | ConvertTo-PodeWebOption -SelectedOption 'Option1'
)
```

The `Update-PodeWebCheckbox` action sees the same update as well - where `-OptionId` is now `-Options`, and can be used to overwrite all options for a Checkbox (like you can with a Select)

Additionally `Enable-PodeWebCheckbox` and `Disable-PodeWebCheckbox` have had their `-OptionId` renamed to `-OptionName`. Instead of referencing an option by its "index", you can now just reference it by the `-Name` supplied to `New-PodeWebOption`.

Furthermore, new Actions have been created to Add, Remove, Select, Reset, and Clear Checkbox options.

### Radios

Radio elements have seen a similar update to Selects and Checkboxes; originally you would create a Radio via `New-PodeWebRadio` and supply `-Options` as a string array, and optionally `-DisplayOptions`.

Now, you can create Options via the new `New-PodeWebOption` function. The `-Options` on `New-PodeWebRadio` now accepts an array of these elements, and the `-DisplayOptions` parameter has moved to `New-PodeWebOption` as `-DisplayName`.

For example, the following previous Radio element:

```powershell
New-PodeWebRadio -Name 'Example' -Options @('Option1', 'Option2')
```

Would now be the following instead:

```powershell
New-PodeWebRadio -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1' -Selected
New-PodeWebOption -Name 'Option2'
)
```

To assist with most migrations there is a helper function: `ConvertTo-PodeWebOption`. You can pipe an original raw string array into this, and it will convert to strings into Option elements for you:

```powershell
New-PodeWebRadio -Name 'Example' -Options @(
'Option1', 'Option2' | ConvertTo-PodeWebOption -SelectedOption 'Option1'
)
```

Furthermore, the Radio elements finally have Update, Add, Remove, Select, etc. Actions - akin to Checkboxes.

## Classes and Styles

Expand Down
172 changes: 157 additions & 15 deletions docs/Tutorials/Actions/Checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,68 @@

This page details the actions available to Checkboxes.

## Add

To add one or more Options you can use [`Add-PodeWebCheckboxOption`](../../../Functions/Actions/Add-PodeWebCheckboxOption) along with `-Option`:

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1'
New-PodeWebOption -Name 'Option2'
)

New-PodeWebButton -Name 'Add Option' -ScriptBlock {
Add-PodeWebCheckboxOption -Name 'Example' -Option @(
New-PodeWebOption -Name 'Added1'
)
}
)
```

## Clear

To clear the options of a Checkbox element, you can use [`Clear-PodeWebCheckbox`](../../../Functions/Actions/Clear-PodeWebCheckbox):

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1'
New-PodeWebOption -Name 'Option2'
New-PodeWebOption -Name 'Option3'
)

New-PodeWebButton -Name 'Clear Checkbox' -ScriptBlock {
Clear-PodeWebCheckbox -Name 'Example'
}
)
```

## Disable

To enable a checkbox you can use [`Disable-PodeWebCheckbox`](../../../Functions/Actions/Disable-PodeWebCheckbox):
To disable a checkbox you can use [`Disable-PodeWebCheckbox`](../../../Functions/Actions/Disable-PodeWebCheckbox):

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Enable' -AsSwitch
New-PodeWebCheckbox -Name 'Example' -AsSwitch

New-PodeWebButton -Name 'Disable Checkbox' -ScriptBlock {
Disable-PodeWebCheckbox -Name 'Enable'
Disable-PodeWebCheckbox -Name 'Example'
}
)
```

For a Checkbox with single or multiple options, this will disable all options. For a Checkbox with multiple options you can specify which option to disable using the `-OptionName` parameter:

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1'
New-PodeWebOption -Name 'Option2'
)

New-PodeWebButton -Name 'Disable Option1' -ScriptBlock {
Disable-PodeWebCheckbox -Name 'Example' -OptionName 'Option1'
}
)
```
Expand All @@ -22,31 +74,121 @@ To enable a checkbox you can use [`Enable-PodeWebCheckbox`](../../../Functions/A

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Disabled' -AsSwitch -Disabled
New-PodeWebCheckbox -Name 'Example' -AsSwitch -Disabled

New-PodeWebButton -Name 'Enable Checkbox' -ScriptBlock {
Enable-PodeWebCheckbox -Name 'Disabled'
Enable-PodeWebCheckbox -Name 'Example'
}
)
```

## Update
For a Checkbox with single or multiple options, this will enable all options. For a Checkbox with multiple options you can specify which option to enable using the `-OptionName` parameter:

To update a checkbox to be checked/unchecked, or to enable/disable, you can use [`Update-PodeWebCheckbox`](../../../Functions/Actions/Update-PodeWebCheckbox):
```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1' -Disabled
New-PodeWebOption -Name 'Option2'
)

New-PodeWebButton -Name 'Enable Option1' -ScriptBlock {
Enable-PodeWebCheckbox -Name 'Example' -OptionName 'Option1'
}
)
```

## Remove

To remove one or more Options you can use [`Remove-PodeWebCheckboxOption`](../../../Functions/Actions/Remove-PodeWebCheckboxOption) along with `-OptionName`:

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Enabled' -AsSwitch
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1'
New-PodeWebOption -Name 'Option2'
New-PodeWebOption -Name 'Option3'
)

New-PodeWebButton -Name 'Update Checkbox' -ScriptBlock {
$checked = [bool](Get-Random -Minimum 0 -Maximum 2)
Update-PodeWebCheckbox -Name 'Enabled' -Checked:$checked
New-PodeWebButton -Name 'Remove Options' -ScriptBlock {
Remove-PodeWebCheckboxOption -Name 'Example' -OptionName 'Option1', 'Option3'
}
New-PodeWebButton -Name 'Enable Checkbox' -ScriptBlock {
Update-PodeWebCheckbox -Name 'Enabled' -Checked:$false -State Enabled
)
```

## Reset

To reset/deselect options of a Checkbox element, you can use [`Reset-PodeWebCheckbox`](../../../Functions/Actions/Reset-PodeWebCheckbox):

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1' -Selected
New-PodeWebOption -Name 'Option2'
New-PodeWebOption -Name 'Option3'
)

New-PodeWebButton -Name 'Deselect Option' -ScriptBlock {
Reset-PodeWebCheckbox -Name 'Example' -OptionName 'Option1'
}
New-PodeWebButton -Name 'Disable Checkbox' -ScriptBlock {
Update-PodeWebCheckbox -Name 'Enabled' -Checked:$false -State Disabled
)
```

## Select

To select options of a Checkbox element, you can use [`Select-PodeWebCheckbox`](../../../Functions/Actions/Select-PodeWebCheckbox):

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Example' -Options @(
New-PodeWebOption -Name 'Option1'
New-PodeWebOption -Name 'Option2'
New-PodeWebOption -Name 'Option3'
)

New-PodeWebButton -Name 'Select Option' -ScriptBlock {
Select-PodeWebCheckbox -Name 'Example' -OptionName 'Option2'
}
)
```

## Sync

If you built a Checkbox element with the `-ScriptBlock` parameter, then you can re-invoke the scriptblock to update the element by using [`Sync-PodeWebCheckbox`](../../../Functions/Actions/Sync-PodeWebCheckbox):

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheck -Name 'Example' -ScriptBlock {
foreach ($i in (1..10)) {
Get-Random -Minimum 1 -Maximum 10
}
}

New-PodeWebButton -Name 'Sync Checkbox' -ScriptBlock {
Sync-PodeWebCheckbox -Name 'Example'
}
)
```

## Update

You can update a Checkbox element's options by using [`Update-PodeWebCheckbox`](../../../Functions/Actions/Update-PodeWebCheckbox):

```powershell
New-PodeWebContainer -NoBackground -Content @(
New-PodeWebCheckbox -Name 'Example' -ScriptBlock {
foreach ($i in (1..10)) {
Get-Random -Minimum 1 -Maximum 10
}
}

New-PodeWebButton -Name 'New Options' -ScriptBlock {
$options = @(foreach ($i in (1..10)) {
Get-Random -Minimum 1 -Maximum 10
})

$options |
ConvertTo-PodeWebOption |
Update-PodeWebCheckbox -Name 'Example'
}
)
```
Expand Down
8 changes: 4 additions & 4 deletions docs/Tutorials/Actions/Datalist.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ New-PodeWebContainer -NoBackground -Content @(
)
```

## Set
## Select

To set the currently selected option/value of a Datalist element, you can use [`Set-PodeWebDatalist`](../../../Functions/Actions/Set-PodeWebDatalist). You can either set the value to a predefined option, or to a custom value not in the options list:
To set the currently selected option/value of a Datalist element, you can use [`Select-PodeWebDatalistOption`](../../../Functions/Actions/Select-PodeWebDatalistOption). You can either set the value to a predefined option, or to a custom value not in the options list:

```powershell
New-PodeWebContainer -NoBackground -Content @(
Expand All @@ -72,11 +72,11 @@ New-PodeWebContainer -NoBackground -Content @(
New-PodeWebButton -Name 'Update Datalist Predefined' -ScriptBlock {
$rand = Get-Random -Minimum 0 -Maximum 3
$opt = (@('Option1', 'Option2', 'Option3'))[$rand]
Set-PodeWebDatalist -Name 'Example' -Value $opt
Select-PodeWebDatalistOption -Name 'Example' -Value $opt
}

New-PodeWebButton -Name 'Update Datalist Custom' -ScriptBlock {
Set-PodeWebDatalist -Name 'Example' -Value 'Custom Value'
Select-PodeWebDatalistOption -Name 'Example' -Value 'Custom Value'
}
)
```
Expand Down
6 changes: 4 additions & 2 deletions docs/Tutorials/Actions/Error.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ New-PodeWebCard -Content @(
} -Content @(
New-PodeWebTextbox -Name 'Name'
New-PodeWebTextbox -Name 'Password' -Type Password -PrependIcon Lock
New-PodeWebCheckbox -Name 'Checkboxes' -Options @('Terms', 'Privacy') -AsSwitch
New-PodeWebCheckbox -Name 'Checkboxes' -Options @(
'Terms', 'Privacy' | ConvertTo-PodeWebOption
) -AsSwitch
New-PodeWebSelect -Name 'Role' -Multiple -Options @(
@('User', 'Admin', 'Operations') | ConvertTo-PodeWebOption
'User', 'Admin', 'Operations' | ConvertTo-PodeWebOption
)
)
)
Expand Down
12 changes: 8 additions & 4 deletions docs/Tutorials/Actions/Form.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ New-PodeWebCard -Content @(
New-PodeWebForm -Name 'Example' -ScriptBlock {} -Content @(
New-PodeWebTextbox -Name 'Name'
New-PodeWebTextbox -Name 'Password' -Type Password -PrependIcon Lock
New-PodeWebCheckbox -Name 'Checkboxes' -Options @('Terms', 'Privacy') -AsSwitch
New-PodeWebCheckbox -Name 'Checkboxes' -Options @(
'Terms', 'Privacy' | ConvertTo-PodeWebOption
) -AsSwitch
New-PodeWebSelect -Name 'Role' -Multiple -Options @(
@('User', 'Admin', 'Operations') | ConvertTo-PodeWebOption
'User', 'Admin', 'Operations' | ConvertTo-PodeWebOption
)
)
)
Expand All @@ -34,9 +36,11 @@ New-PodeWebCard -Content @(
New-PodeWebForm -Name 'Example' -ScriptBlock {} -Content @(
New-PodeWebTextbox -Name 'Name'
New-PodeWebTextbox -Name 'Password' -Type Password -PrependIcon Lock
New-PodeWebCheckbox -Name 'Checkboxes' -Options @('Terms', 'Privacy') -AsSwitch
New-PodeWebCheckbox -Name 'Checkboxes' -Options @(
'Terms', 'Privacy' | ConvertTo-PodeWebOption
) -AsSwitch
New-PodeWebSelect -Name 'Role' -Multiple -Options @(
@('User', 'Admin', 'Operations') | ConvertTo-PodeWebOption
'User', 'Admin', 'Operations' | ConvertTo-PodeWebOption
)
)
)
Expand Down
Loading