fresh2dev / AnyBox

The easiest way to develop apps for Windows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default value on set

kalivodv opened this issue Β· comments

Hi Donald,

I would like to thank you for AnyBox module, it's really great πŸ‘ and I have decided to use it in one of my projects :)

Still, I am experiencing one issue. If I try to set parameter -DefaultValue together with -ValidateSet and -ShowSetAs ComboBox, I am not getting the default value. With -ShowSetAs Radio, default value is working as expected.

$prompts = @(
        
            (New-AnyBoxPrompt -InputType Text -Message 'Username'),
            (New-AnyBoxPrompt -ValidateSet @('group1', 'group2', 'group3') -ShowSetAs ComboBox -DefaultValue 'group2' -Message 'Group'),
            (New-AnyBoxPrompt -ValidateSet @('5 GB', '10 GB') -ShowSetAs Radio -DefaultValue '10 GB' -Message 'Quota')
)

$buttons = @(

            'Save',
            'Quit'
            
)

$answer = Show-AnyBox -Title 'New User' -Prompts $prompts -Buttons $buttons

image

Could you please help me with this issue?

Regards
Viktor

Unfortunately, I wasn't able to solve this. But I found temporary solution.
As workaround:

  • I have added index numbers to every object in all of my arrays
  • changed one line in Show-AnyBox.ps1 that seems to be problematic - under if ($prmpt.ShowSetAs -eq [AnyBox.SetPresentation]::ComboBox):
if ($prmpt.DefaultValue) {
    $inBox.SelectedItem = $prmpt.DefaultValue
}

changed to:

if ($prmpt.DefaultValue) {
    $inBox.SelectedIndex = $prmpt.DefaultValue
}

So the working example now looks like:

$groups = @('group1', 'group2', 'group3')
$i = -1
$groupsarray = @()

foreach ($one in $groups){

    $i++
    $groupsobject = New-Object PSobject
    $groupsobject | Add-Member -MemberType NoteProperty -Name Name -Value $one
    $groupsobject | Add-Member -MemberType NoteProperty -Name Nr -Value $i
    $groupsarray += $groupsobject

}

$defaultgroup = "group2"
$defaultgroupindex = ($groupsarray | Where-Object {$_.Name -eq $defaultgroup}).Nr


$prompts = @(
        
            (New-AnyBoxPrompt -InputType Text -Message 'Username'),
            (New-AnyBoxPrompt -ValidateSet $groupsarray.Name -DefaultValue $defaultgroupindex -Message 'Group'),
            (New-AnyBoxPrompt -ValidateSet @('5 GB', '10 GB') -ShowSetAs Radio -DefaultValue '10 GB' -Message 'Quota')
)

$buttons = @(

            'Save',
            'Quit'
            
)

$answer = Show-AnyBox -Title 'New User' -Prompts $prompts -Buttons $buttons

image

I know it's crazy a bit, but I was really hopeless πŸ˜ƒ

Viktor

commented

Viktor, thank you for bringing this to my attention. This bug has been fixed in the 'dev-master' branch and will soon be merged into 'master'.

c5a668a