Skip to content

Can't set value of select type field in form for edit #1299

Closed

Description

@Flugelman

I've combed over the docs, tried a lot of things, and I cannot see any way to set the value of a search field using select and option_source in an edit form.

It works fine from scratch on my add form to make a new record, but in the edit form on an existing record this field always comes up blank. I've tried setting value, selected, and label_value at the row level in the form SQL, I've tried using some json like this (per a forum post):

select 'json' as component;

SELECT 
  tracks.id AS value, 
  tracks.title AS label,
  tracks.id = CAST($track_key AS INT) AS selected
FROM tracks
WHERE lower(title) LIKE '%' || lower($search) || '%';

But that fails with an error message saying that the json array only supports label and value keys.

So how exactly does one successfully use a select type with a pre-set value for edit?

thanks!

Activity

  1. lovasoa commented on Jun 8, 2026

    @lovasoa
    Collaborator

    Hi !

    Thanks for the detailed report.

    There is no clean way to do what you want with options source, but here is a workaround:

    select 'shell' as component, 'options_source edit workaround' as title;
    
    select 'text' as component, 'Edit record with remote-search select' as title;
    
    select 'form' as component, 'Submit' as validate, 'post' as method, 'index.sql' as action;
    
    select
        'select' as type,
        'track_id' as name,
        'Track' as label,
        id as value,
        true as searchable,
        'tracks.sql' as options_source,
        json_group_array(json_object('value', id, 'label', title)) as options,
        'The current edit value is preloaded, and more options load as you search.' as description
    from tracks
    where id = 2;

    I'll see if we can have a proper fix in the next version

  2. linked a pull request that will close this issueDocument select options_source behavior #1300on Jun 8, 2026
  3. lovasoa commented on Jun 8, 2026

    @lovasoa
    Collaborator

    I ended up updating just the documentation. I think combining options and options_source is actually a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions