lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.ophir.dev
MIT License
883 stars 64 forks source link

Form value not submitted with the dropdown / select type #482

Closed castlekaybee closed 3 days ago

castlekaybee commented 3 days ago

Introduction

in a form component, using a select type (dropdown) with the name property (e.g. mySeleectedValue)

after form submisson the value identified by the name property is empty (:mySelectedValue)

To Reproduce

To test the submitted data:

select 'text' as component,
:Aggregatstyp as title,
$br_id_from_url as contents;

This works as expected:

SELECT 'form' AS component,
    'Aggregat auswählen' AS title,
    'Hinzufügen' as validate,
    'teal' as validate_color,
    '/UI/Maschinen/QueryMaschinenteilInsert.sql?br_id_from_url=' || $br_id_from_url AS action;

SELECT 'Aggregatstyp' AS name,
  1 AS required;

image image

This does not submit a value for 'Aggregatstyp':

SELECT 'form' AS component,
    'Aggregat auswählen' AS title,
    'Hinzufügen' as validate,
    'teal' as validate_color,
    '/UI/Maschinen/QueryMaschinenteilInsert.sql?br_id_from_url=' || $br_id_from_url AS action;

SELECT 'Aggregatstyp' AS name,
  1 AS required  ,
  'select' as type,
  (SELECT
      AG_ID AS id,
      Aggregat AS label
  FROM
      AbfrageAggregatsListe
  FOR JSON AUTO) as options;

image image

Version information

castlekaybee commented 3 days ago

this is the result from the query to the server:

SELECT
       AG_ID AS id,
       Aggregat AS label
   FROM
   AbfrageAggregatsListe
  FOR JSON AUTO;
[{"id":4,"label":"AN-TB-411"},{"id":6,"label":"PF-TB-559"},{"id":7,"label":"FD-leer-482"},{"id":8,"label":"FD-leer-482"},{"id":9,"label":"FD-leer-492"},{"id":10,"label":"FD-leer-492"},{"id":11,"label":"FD-leer-582"},{"id":12,"label":"FD-leer-592"},{"id":13,"label":"FD-leer-852"},{"id":14,"label":"FD-leer-862"},{"id":15,"label":"BA-B-524"},{"id":16,"label":"BA-B-525"},{"id":17,"label":"BA-B-526"},{"id":18,"label":"BA-B-527"},{"id":19,"label":"BA-S-524"},{"id":20,"label":"BA-S-525"},{"id":21,"label":"BA-S-526"},{"id":22,"label":"BA-S-527"},{"id":23,"label":"BA-VT-520"},{"id":24,"label":"BA-VT-521"},

...,

{"id":264,"label":"RS-874"},{"id":265,"label":"VQ-875"},{"id":266,"label":"FC-876"},{"id":267,"label":"SC-117"},{},{},{}]
lovasoa commented 3 days ago

Hello ! I am really sorry, it's my previous answer in https://github.com/lovasoa/SQLpage/discussions/480 that contained an error. As stated in the documentation, the accepted keys in the json objects of the options property of the form component are :

(there is no id, contrarily to what my previous answer suggested)

So you query should look like this instead:

SELECT 'Aggregatstyp' AS name,
  1 AS required  ,
  'select' as type,
  (SELECT
      AG_ID AS value, -- value, not id
      Aggregat AS label
  FROM
      AbfrageAggregatsListe
  FOR JSON AUTO) as options;
castlekaybee commented 3 days ago

Thanks for spotting this. Now it works as expected 👍