Text field "is not empty" does not store properly to database if text input has spaces

I have a form with 4 text inputs and when the user submits I’m trying to store their data in the database in a single list of texts.

If I have no error checking for empty fields, it works but ends up storing a null value for any non populated text fields. To work around this I’m trying to add “is not empty”. When each text field has “is not empty” any field where a user entered a string with a space in it does not appear in the database.

Is this a bug or am I doing something wrong?

Could you share a link to your app or replicate your setup in the forum app?

1 Like

If you added a when condition in the workflow action that said when “input’s value:trimmed is not empty”, it should strip the spaces out and then evaluate if it’s empty.


https://forum_app.bubbleapps.io/version-test/create_question/sample:custom.question?debug_mode=true

You can see here if you list a few options it is storing null values in the database

Ultimately, I’m trying to display a radio button element to users so that they can answer questions. In this instance it would be creating an extra radio button with a null value.

Was the provided forum example helpful?

Checking this out now. One moment.

Ok, @john2. Check out the screenshots that go with my explanation and also get in the app to study what I did and let me know if this is what you wanted to achieve.

First, I changed your data structure a little. Each answer gets its own text field. A little more flexibility this way. Each question and set of answers will still be its own entry in your database and you can refer to it either by unique ID or add a user field (type user) to attach it to a specific user.

Then I adjusted the submit button accordingly…

Now, I went ahead and created the radio button element since that was your goal anyway. I put the element inside the repeating group you created to quickly access the desired question (current cell’s question/answer). The source is basically a merging of each answer text field. Since the element is looking for a list, you need to start this source expression with a search of the database (not just current Q/A’s answer 1) and filter it to answer 1, then you can use “plus item” to add the rest. Click on the “search for…” part in the app to see that I constrained it by unique id [unique id= current cell’s unique id].

Now, when you click submit and a field is empty, nothing is stored in that field, but the radio button’s source has been told that there are to be 4 choices, so it’s going to display 4 buttons no matter what. This is actually less of a null field issue and more just the structure of the radio button element - it doesn’t remove a button if the choice is empty. SO, I started you off with a 3 option scenario by creating a condition on the element. When answer 4 is empty, the choice source changes to exclude answer 4. Do this 2 more times for when answers 3 & 4 are empty and when 2, 3, & 4 are empty. I’d also create some conditions that your fields should be answered in order so that your users don’t go just filling out answer 4 and not the rest.

Let me know if this helps!

5 Likes

Wow, this is very helpful, thank you! I’m curious though why I couldn’t get it to work right using a list in the database as it would if I were programming it from scratch using python & sql. This method you presented works but is much less straightforward than the way I was trying to go about it and almost seems like a workaround for something that should function differently. Maybe a bubble dev could chime in as to why this isn’t so?

I can’t speak to comparisons to other code (I have zero knowledge there), but I imagine you could still do it with a list and in the source have list item #1 plus list item #2. However to avoid the null item being saved, I think you’d still have to create multiple events and/or conditions to account for empty and not empty fields… I didn’t attempt that route as it seemed like it was getting more complicated. There are usually a few ways to accomplish the same thing, some are just more efficient. I’m not saying my route was the most efficient - someone else could have a different approach that’s more straight-forward, but this is how my brain did it! I’d be interested in seeing another approach!

1 Like

Ah I see, the issue really is preventing that null value from getting stored which is what I thought “is not empty” was supposed to prevent. I might try this alternate idea you proposed and if not go with what you came up with. Ideally if a field was null or empty it shouldn’t append it to the list, or there should be a way to prevent it from being appended.

I edited the test page to make a list field work… It would mean creating an event for every scenario though unless you want to create required number of answers. So for when all fields contain text, the event is “when button is clicked and all inputs are not empty” add all to the list. If field 2 is empty, “when button is clicked and input 2 is empty” add 1,3,4 to list.

Check it out:

For some reason, in the test example I can’t enter only two options. If I do that I still get an empty radio button option. I tried adding an extra check for if answer 3 and answer 4 are both empty but it doesn’t work right.

Ah I got it! I forgot to add the constraint for unique ID to the second check for empty answer 3 and 4. Thanks again!!