Closed Stephanevg closed 5 years ago
Ideally, I would see something around the lines:
New-PSHTMLDropDownList -Items$
The $Items elements could be created indenpendently as followed
New-PSHTMLDropDownListItem -Value "Green" -Content "Green"
Scaling it out
$AllItems = @()
Foreach($FavoriteColor in $Colors) {
$AllItems += New-PSHTMLDropDownListItem -Value $FavoriteColor -Content $FavoriteColor
}
It will be combined as followed:
New-PSHTMLDropDownList -Items $AllItems
Made this two small functions ... tell me if this suits you, or if you were looking at something different !
Edit: Added Pipeline support for New-PSHTMLDropDownList. If you pass an array of string it'll automatically transform it to dropdown items. You can also directly pipe an array of already well formated drop down elements.
function New-PSHTMLDropDownList {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
PS C:\> $items = 'apples','oranges','tomatoes','blueberries'
PS C:\> $items | New-PSHTMLDropDownList
Create new simple dropdownlist, array based, from the pipeline. Also work with an array of drop down options
.EXAMPLE
PS C:\> $items = 'apples','oranges','tomatoes','blueberries'
PS C:\> New-PSHTMLDropDownList -Items $Items
Create new simple dropdownlist, array based
.EXAMPLE
PS C:\> $ArrayOfDropDownOptions = @()
PS C:\> $items = 'apples','oranges','tomatoes','blueberries'
PS C:\> Foreach ( $item in $items ) { $ArrayOfDropDownOptions += New-PSHTMLDropDownListItem -value $item -content $item }
PS C:\> New-PSHTMLDropDownList -Items $ArrayOfDropDownOptions
Create new simple dropdownlist, array based
.INPUTS
Inputs (if any)
.OUTPUTS
Output (if any)
.NOTES
General notes
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $False,ValueFromPipeline=$True)]
[AllowNull()]
[Array]
$items,,
[AllowEmptyString()]
[AllowNull()]
[String]$Class,
[String]$Id,
[Hashtable]$Attributes
)
begin {
$Option = @()
}
process {
If ( $null -ne $items ) {
## Assuming its coming from New-PSHTMLDropDownListItem
If ( $items[0] -match '^<option') {
$Option += $items
} Else {
Foreach ( $item in $items ) {
$Option += New-PSHTMLDropDownListItem -value $item -Content $item
}
}
}
}
end {
selecttag -Content {
$option
} -Class $Class -Id $Id -Attributes $Attributes
}
}
function New-PSHTMLDropDownListItem {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
PS C:\> New-PSHTMLDropDownListItem -value 'aaaa' -content 'aaaaaaa'
Create a new dropdown option
.INPUTS
Inputs (if any)
.OUTPUTS
Output (if any)
.NOTES
General notes
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[AllowEmptyString()]
[AllowNull()]
$Content,
[string]$value,
[string]$label,
[Switch]$Disabled,
[Switch]$Selected,
[AllowEmptyString()]
[AllowNull()]
[String]$Class = "",
[String]$Id,
[AllowEmptyString()]
[AllowNull()]
[String]$Style,
[String]$title,
[Hashtable]$Attributes
)
begin {
}
process {
option @PSBoundParameters
}
end {
}
}
Awesome @LxLeChat ! thank you so much for your PR man!!
PSHTML code