# Alert but not prevent the user entering a duplicated value in a field

**URL:** <https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952>\
**Category:** Ask the Community\
**Created:** [26 September 2026 16:46 UTC](https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952 "2026-09-26T16:46:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jp136769](https://dub1.discourse-cdn.com/flex018/user_avatar/community.qfield.org/jp136769/32/1551_2.png) [@jp136769](https://community.qfield.org/u/jp136769)\
**Post date:** [26 September 2026 16:46 UTC](https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952/1 "2026-09-26T16:46:45Z")

</div>

Hi all,

Given a simple form for a layer with a field “Name”, I need this field to be set, an in a specific format : non null + enforce expression constraint. That’s OK.  
Now on top of that, how to alert the user if his entry already exists in this field “Name”. Just an alert _It’s not unique, you’ve been warned_.  
A small text in orange, complementary to the red text related to the constraints criterion.

Thanks!

---

<div class="post-metadata">

**Author:** ![cuprico](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@cuprico](https://community.qfield.org/u/cuprico)\
**Post date:** [26 September 2026 23:24 UTC](https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952/2 "2026-09-26T23:24:27Z")

</div>

I think you just need to not enable the `Enforce unique constraint` right beside the `Unique` checkbox on the attribute’s form:

 ![image](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/2X/e/ea7bf29b8546b1189b6a070c046e9ef6a1253301.jpeg)

QField then would follow the same behaviour as QGIS, painting the field orange while you populate it to let you know that it is _not_ unique, but would just let you save it anyways.

---

<div class="post-metadata">

**Author:** ![jp136769](https://dub1.discourse-cdn.com/flex018/user_avatar/community.qfield.org/jp136769/32/1551_2.png) [@jp136769](https://community.qfield.org/u/jp136769)\
**Post date:** [27 September 2026 06:56 UTC](https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952/3 "2026-09-27T06:56:57Z")

</div>

Thanks @cuprico , I tried that: the behavior is as you described in QGIS, but in QField, the constraint seems to be interpreted as an enforced one.

 ![image](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/2X/a/a1fe7b33d9a6d12246a90fb2282d9e27bb587347.png)

In QField, I see in red my constraint by expression, not null, and unique.  
Can’t add a duplicate.

---

<div class="post-metadata">

**Author:** ![cuprico](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@cuprico](https://community.qfield.org/u/cuprico)\
**Post date:** [27 September 2026 19:05 UTC](https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952/4 "2026-09-27T19:05:55Z")

</div>

hmm, have you tried without the expression constraint? I seem to remember the orange warning, maybe there can only be a single warning shown at a time (as I remember the space for the error message to be quite small, in-between the top empty space of the attribute field).

Maybe you can enforce the constraint in a different way. What about, for example, spliting the attribute into two:

- One numeric integer field, with the only constraint being limiting it to 999 or below. I think you can add the 0 padding afterwards with an expression, and this would speed the user’s input of the number.
- Another attribute of type text, maybe called something like “suffix letter”. On it, you can give a dropdown to the user to pick the correct letter, instead of an usual typing field. The interaction itself would limit what the user can input.

Then, if you would really like to have an attribute with the full name, it can be a third one, hidden from the user and autopopulated (using a “default value” expression) with those two fields.

---

<div class="post-metadata">

**Author:** ![Jeroen-GroeneBij](https://dub1.discourse-cdn.com/flex018/user_avatar/community.qfield.org/jeroen-groenebij/32/905_2.png) [@Jeroen-GroeneBij](https://community.qfield.org/u/Jeroen-GroeneBij)\
**Post date:** [28 September 2026 08:53 UTC](https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952/5 "2026-09-28T08:53:03Z")

</div>

I have been testing this and it seems QField does not differentiate between enforcing or not enforcing the unique constraint, QField treats the Unique constraint always as Enforced

The Not Null constraint by itself has the correct behaviour: when Enforce is not checked, it will show as orange and you can save a NULL value  
The Expression constraint by itself has the correct behaviour: when Enforce is not checked, it will show as orange and you can save a value that does not match your expression  
The Unique constraint, even by itself does not have the correct behaviour: even when Enforce is not checked, you are not allowed to fill in a duplicate value.

This has to be a bug in QField.  
I have just now filed it as a bug: [Unique constraint is always treated as Enforced · Issue #8069 · opengisch/QField · GitHub](https://github.com/opengisch/QField/issues/8069)

---

<div class="post-metadata">

**Author:** ![jp136769](https://dub1.discourse-cdn.com/flex018/user_avatar/community.qfield.org/jp136769/32/1551_2.png) [@jp136769](https://community.qfield.org/u/jp136769)\
**Post date:** [28 September 2026 10:45 UTC](https://community.qfield.org/t/alert-but-not-prevent-the-user-entering-a-duplicated-value-in-a-field/1952/6 "2026-09-28T10:45:27Z")

</div>

Hi @Jeroen-GroeneBij, @cuprico ,

By now, to get a simple alert about the unicity, I’ve opted for this :

 ![image](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/2X/3/3f4ce96ee9fca5641b53ae6a997627659b4ab144.png)

It shows the orange flag but permits the record.

I’ve retained @cuprico proposition with two different fields, one for the site number, another for the suffix. Both are mandatory and unique.  
I’ve created another “full\_name” field (virtual one), populated with the expression needed to format the record. This field is hidden. And the screenshot above shows how both the flexible unique constraint and the auto update of the “full\_name” field are managed to trigger the alert.  
Thank you both for your support.

I close the topic as my specific need is solved, but I confirm unique constraint is always treated as Enforced. Thank you for opening the ticket.
