lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.datapage.app
MIT License
1.29k stars 69 forks source link

Global variable support #130

Closed Pieter3033 closed 9 months ago

Pieter3033 commented 9 months ago

Hi,

Is it possible to add global variable support, across all of my SQLPage webpages. I could be wrong, but I believe this is not a feature in SQLPage.

Currently I am working with 3 different form submissions, which updates a single row in my database. This row has to be updated later on a separate page.

The reason I am using 3 form submissions is: 1st Form, The user Selects a Client. (Using a select box) (Creates a row) 2nd Form, The user Selects a Fleet based on the Client selected in the previous form. (Using a select box) (Updates the created row) (The use of pre-defined select boxes allows me to prevent human error) 3rd Form, The user Submits information that has to update the row created in the first form.

Currently I am setting the type = hidden, essentially populating the input with a reference number that has been auto generated in the previous form and carrying it over the forms. I get the same results when setting the input to readonly. Without this I have no way of referencing which row to update in the database.

The problem with this solution it is not as neat, because it either results in a blank space or a input box with no purpose.

Possible solution:

I am not sure if it is possible, but keeping the already supported local variables syntax mentioned in #49 and enabling it to act as global variables as well?

lovasoa commented 9 months ago

Hello and thanks for the feedback.

I don't think what you need is a global variable. Everything that is global should probably be stored in the database itself. But in your case, if I understand well, the state you want to save is not global but client-specific. If two people are connected to the form at the same time, they don't want to see the same pre-filled values in the second form.

I would have implemented what you are describing in one of three ways:

  1. with hidden form inputs, the way you are doing it. Can you post a screenshot of the "blank space" you are referencing ? I thing the problem to fix is here. Other than that, I don't see a problem with that solution.
  2. with cookies set on the client side, using the cookie component to store the values filled in the previous forms
  3. if we want to persist partially-filled forms in the long term and across devices and user reconnections: with a table in the database that contains the user id and the partially filled form values.
lovasoa commented 9 months ago

I'm closing this for the moment, but I'm open to reopening it if there is something I missed. The discussion is still open.

Pieter3033 commented 9 months ago

Thanks for the advice, I've implemented cookies across the first 2 forms and a unique user_id that automatically increases on the last form submisson and then gets saved in the database accordingly.

When the user want to edit the form I just reference back to the user_id created.

I appreciate your advice, have a good one.

Regards

lovasoa commented 9 months ago

Can you still give a screenshot of your form, with the problematic "blank space" and the corresponding code ? Maybe there is still something to fix in SQLPage on that front ?

lovasoa commented 9 months ago

And by the way, I am giving a talk about SQLPage at pgconf.eu this december, and I'd like to include feedback from users. If you have 15 minutes to chat about what you are using SQLPage for sometimes this week, I'd love to !

Pieter3033 commented 9 months ago

Can you still give a screenshot of your form, with the problematic "blank space" and the corresponding code ? Maybe there is still something to fix in SQLPage on that front ?

Currently I have scraped the idea to use type = hidden, but here is the example. Note this is how I have done it previously.

Using the form component.

Code:

SELECT 
        'srf_notes' AS name
       ,'hidden' AS type

Screenshot: ( Marked in green is the "blank" space ) image

I discovered though, when entering nothing inside of the label parameter(not removing it, just leaving it blank), the problem of the "blank" space is resolved.

Code:

SELECT '' AS label
       ,'srf_notes' AS name
       ,'hidden' AS type 

Screenshot: image

Conclusion: I believe the cookie component Idea is my preference here.

Pieter3033 commented 9 months ago

And by the way, I am giving a talk about SQLPage at pgconf.eu this december, and I'd like to include feedback from users. If you have 15 minutes to chat about what you are using SQLPage for sometimes this week, I'd love to !

Congratulations, I'd love to discuss my project with you! How does tomorrow 14:00 (GMT+2) fit you?

lovasoa commented 9 months ago

image

Ok, I see what you mean !

when entering nothing inside of the label parameter, the problem of the "blank" space is resolved

Just tried it, and there is actually still a small vertical margin that is added at the place of the hidden input.

I will release a new version of SQLPage where hidden inputs are really completely hidden. I think there should be no visual difference between a form that has a hidden field and the same form without that field. Thank you for bringing this to my attention !

I'd love to discuss my project with you! How does tomorrow 14:00 (GMT+2) fit you?

:blush: I'll be in a meeting at that time, unfortunately. Can you do the evening (after 7pm GMT+2), or friday morning ? You can contact me on contact@ophir.dev.