Form Repeater creates records even when no data is added to fields

Wappler Version : 6.8.0
Operating System : Windows 10 Pro
Server Model: Node
Database Type: Postgres
Hosting Type: Local (Supabase for DB)

Expected behavior

When you add new rows to the Form Repeater, don't type anything in the fields, and simply submit the form, the empty fields should be ignored since they contain no information.

PS: "URL" is the input label.

Actual behavior

After submitting the form, blank (not null) records are created in the database, which even bypasses the "not null" rule applied to the URL field.

Additional information:

By default, I was leaving one row initially visible, so the user wouldn’t have to go through the trouble of clicking the "+ URL" button. I expected the form to ignore a field that wasn’t filled out. But since this empty record is being created, I started hiding the initial row (Items = 0) but, apparently, I can't submit a Form Repeater without fields. In my tests, if I want to keep an OPTIONAL section where the user can add related URLs to the main record, I need to keep at least one row visible. And if nothing is typed in the field, an "empty" not null record will be created in the database.

If I try to submit a Form Repeater without any rows, the API returns the following error:

image

I'm not sure if there's a workaround for this.

Hi Ivan,

The field in the database is showing a blank value, which is not the same as <null>.

If the URL input field is an optional field, then set the field type in the database to allow null values and add a default formatter to the $_POST variable like this to insert null if no user input is available: {{$_POST.path.default(null)}}.

Hi, Shalabh! Thanks for your reply.

Let me give you one more piece of information.

In summary, the user can create a Product and optionally associate one or more links to it in a separate table. Adding links is optional, but the "path" field is mandatory, as it wouldn't make sense for the user to associate a link without entering its address (blank or null).

I was expecting empty rows to be ignored, or alternatively, that Form Repeaters without rows would also be ignored.

If the insert API step has been setup as a nested insert (main -> sub table), then I would look at inserting the records in the main and sub tables separately, where you can check conditionally whether the $_POST.formRepeat1.path value is empty or contains a value.

The API steps will look like this. You will need at least 1 formRepeat row for this API to work. Otherwise, the first step will insert the record, but it will also generate an error if no $_POST.formRepeat1 value is available from the server connect form.

1 Like

Hello again!

I ended up implementing a solution very similar to what you suggested, with a conditional to ignore empty URLs. I also made some changes to the frontend to prevent Form Repeaters from being submitted without rows. Thanks for your help anyway!

I still consider this topic a bug report for the component since we had to create workarounds for a behavior that doesn’t seem natural to me. Hopefully, the team will look into the issue.

1 Like

Following this excellent tutorial

If you leave Items blank, there will be no empty records placed in the database.

image

I don't see a bug here, that's how forms work.
If you submit an empty input, it sends an empty string to the servers side so an empty string is stored in the database. Empty string is still a string, it's not a null value.

Thanks, Ben! I'm familiar with that tutorial. It uses a single page, which makes things a lot easier. My form has multiple tabs, and a lot is happening simultaneously.

Anyway, I'll recreate other use cases in a controlled environment when I have more time, to deepen my understanding of the component.

1 Like

I still find it inconsistent, but since the workaround is working, I'll accept it for now. Later on, with more time, I'll refine my perception of it. Thanks!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.