Skip to content

Form Builder: picker initial value is not set correctly #521

Description

@charlieTheBotDev

Context

The addPicker method allows you to pass values through to the hx.Picker using pickerOptions which includes the initial value. When the picker is not required in the form, the value is then set to the value of the first item in the list.

The intended code is as follows:

new hx.Form(hx.select('body').clear().append('form'))
  .addPicker('Select', ['red', 'green', 'blue'], { pickerOptions: { value: 'blue' } })

Expected Behavior

The picker should have the value of blue

Actual Behavior

The picker uses the first value and has red

Possible Fix

  • Update the point where the first value is set to detect if the value is already being set with pickerOptions.value and use that instead.

Workaround

Passing required: true causes the picker to start with a value and not set the value inside the addPicker method, leaving the desired behaviour.

new hx.Form(hx.select('body').clear().append('form'))
  .addPicker('Select', ['red', 'green', 'blue'], { pickerOptions: { value: 'blue' }, required: true })

Steps to Reproduce

new hx.Form(hx.select('body').clear().append('form'))
  .addPicker('Select', ['red', 'green', 'blue'], { pickerOptions: { value: 'blue' } })

Your Environment

  • Hexagon Version: 1.19.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions