idris-maps / svelte-parts

Svelte components
https://svelte-parts.surge.sh
49 stars 5 forks source link

Default values for unchanged form #7

Closed PlkMarudny closed 2 years ago

PlkMarudny commented 3 years ago

When a form is created from data and submitted, only changed values are evaluated and sent back to the server, for example:

"fields": [
                            {
                                "type": "text",
                                "property": "upper_line",
                                "label": "Upper Line",
                                "notRequired": true
                            },
                            {
                                "type": "text",
                                "property": "bottom_line",
                                "label": "Bottom Line",
                                "notRequired": true
                            },
                            {
                                "type": "date",
                                "property": "onair_date",
                                "label": "Date"
                            },
                            {
                                "type": "checkbox",
                                "property": "12h",
                                "label": "AM/PM",
                                "value": true
                            },
                            {
                            "type": "radio",
                            "property": "pill",
                            "label": "Choose your pill",
                            "options": [
                                "red",
                                "blue"
                            ],
                            "value": ""
                            }
                        ]

Generates the following form: image

Pressing "submit" after setting up a date (required) produces: image

It does not seem possible to receive all the fields with the default values instead (but it would be nice to get them)

image

idris-maps commented 2 years ago

Thank you @PlkMarudny Should be fixed now. If you add a default value of '', it will be returned. Here is your example in the svelte REPL: https://svelte.dev/repl/3a3b457d16f34e40a55ed5b490cef1b8?version=3.43.1