dyaliCode / svelte-formly

Generator dynamic forms for Svelte JS
https://svelte.formly-js.com
MIT License
253 stars 29 forks source link

Select first item #57

Closed webfrank closed 2 years ago

webfrank commented 2 years ago

When using a select field, if left untouched, the shown selected item is not really selected (not returned as values) and it is null in the on:update event.

kamalkech commented 2 years ago

@webfrank thank u for ur investigation, as you said if left untouched ofc the value it will be null because u need add to default value. try to test using this repl bellow: https://svelte.dev/repl/fa8e6cd0c671439e84eb44bca73fc9e3?version=3.49.0

kamalkech commented 2 years ago

@webfrank i close this task because get no feedback

webfrank commented 2 years ago

Hi, sorry for late feedback. It seems that even if I set the value the first item is not reported as selected.

This is field config:

{
  type: 'select',
  name: 'kind',
  value: 'temperature',
  attributes: {
    id: 'kind',
    label: 'Metric',
    classes: ['form-control', 'mb-2']
  },
  extra: {
    options: [
      {
        value: 'temperature',
        title: 'Temperature'
      },
      {
        value: 'humidity',
        title: 'Humidity'
      },
      {
        value: 'batteryPercentage',
        title: 'Battery'
      }
    ]
  }
}

and this is the renderd form

Schermata 2022-08-02 alle 15 44 40

but from the on:update handler I got this:

Schermata 2022-08-02 alle 15 48 06

kind is supposed to be temperature but instead is null.