sqlpage / SQLPage

Fast SQL-only data application builder. Automatically build a UI on top of SQL queries.
https://sql.datapage.app
MIT License
1.57k stars 89 forks source link

Dynamic value for select component in forms #602

Closed accforgithubtest closed 2 weeks ago

accforgithubtest commented 2 weeks ago

I am unsure whether this is a bug report or feature request.

I am trying to get the select component in a form to pre-select an option based on a url param https://....create_activity.sql?activityKey=3

Specifying the value 3 as value works, however $activityKey as value doesn't work.

Is there a way for me to get the pre-select to work based on the url param $activityKey ?

select 
   'form' as component,
   'Add Activity' as validate,
   'GET' as method,
   'create_activity.sql' as action;

select 
    'activity_key' as name,
    'Activity Key' as label,
    'select' as type,
    3 as width,
    true as required,
    JSON_ARRAYAGG( JSON_OBJECT("value", id, "label", value) ) as options,
    -- 3 as value,
    $activityKey as value,
    true as searchable
    from activity_keys;
lovasoa commented 2 weeks ago

Hi! I think what you are looking for is the selected option of the json object in options.

'selected', $key::int = 3
accforgithubtest commented 2 weeks ago

Yes, selected in json options is what I was after. Works perfectly as expected. Thanks for the help.