# Stop callback if fields in form are empty

**URL:** <https://community.plotly.com/t/stop-callback-if-fields-in-form-are-empty/63286>\
**Category:** Dash Python\
**Created:** [April 22, 2022, 12:18am UTC](https://community.plotly.com/t/stop-callback-if-fields-in-form-are-empty/63286 "2022-04-22T00:18:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert\_oc](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/robert_oc/32/18569_2.png) [@robert\_oc](https://community.plotly.com/u/robert_oc)\
**Post date:** [April 22, 2022, 12:18am UTC](https://community.plotly.com/t/stop-callback-if-fields-in-form-are-empty/63286/1 "2022-04-22T00:18:46Z")

</div>

Hello!

I created a form with the html.Form function and a callback to catch the click on the submit button, however I need to validate that the fields have information because they will be stored in fields marked as “not null” in the database. I used the “required” property in the inputs and, as expected, it shows a message asking to fill the fields. However, that doesn’t stop the callback from running and I got an error from the insert to the database.

How can I force the callback to stop when the fields are empty? I suspect that I can check for the values of the fields and if they are empty raise a PreventUpdate exception but I’m not sure this is the best approach.

Has someone made something similar? Could you suggest or share what you did?

Thank you!

---

<div class="post-metadata">

**Author:** ![jcthomas](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jcthomas](https://community.plotly.com/u/jcthomas)\
**Post date:** [April 22, 2022, 2:37pm UTC](https://community.plotly.com/t/stop-callback-if-fields-in-form-are-empty/63286/2 "2022-04-22T14:37:31Z")

</div>

PreventUpdate is exactly what I’d use here, is there some issue with it? It initially seems weird to be raising an error for something that isn’t fatal, but it just silently stops the callback from trigering, which is what I generally want.

---

<div class="post-metadata">

**Author:** ![robert\_oc](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/robert_oc/32/18569_2.png) [@robert\_oc](https://community.plotly.com/u/robert_oc)\
**Post date:** [April 22, 2022, 3:51pm UTC](https://community.plotly.com/t/stop-callback-if-fields-in-form-are-empty/63286/3 "2022-04-22T15:51:20Z")

</div>

No issue. As you said, it seemed weird to raise an exception and I wanted to know if there was another way. But in the end, I wrote the raise exception and is working fine.

Thank you!

---

<div class="post-metadata">

**Author:** ![Emil](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emil/32/31734_2.png) [@Emil](https://community.plotly.com/u/Emil)\
**Post date:** [April 22, 2022, 4:00pm UTC](https://community.plotly.com/t/stop-callback-if-fields-in-form-are-empty/63286/4 "2022-04-22T16:00:39Z")

</div>

Preaching to the choir, I just want to agree that this is indeed the recommended approach 🙂
