Hi Jon,
I’ve just completed the feature we both need. It really rocks!
I had this implemented at several places in my client’s code, but I can now delete all this redundancy and use this new method from now on.
Go see it here: Allow duplicates value on specific fields and words
Just sign-up and you’ll see it in action.
The way the code is done is so that you can have the “N/A” duplicate word as you wanted, but I went a step further and made it to allow specifying more than one field and more than one word for each form.
The new field keyword is _uvx=allowedDup1, allowedDup2,…. Stands for “Unique Value Exceptions”
Ex: _uvx=N/A,Sample
You set it for each field’s description that you need, in the object page.
It uses a hidden Search view and sequences all searches in the background, and pops-up an alert with the details of all duplicates found. If none, the Submit is done automatically and the Item view below is refreshed also using the _rvs=Items keyword.
Here’s the setup for the fields:
In this case, the SKU field will allow
N/A and
Eval as possible duplicates.
The other field (not shown here) is Item and has this keyword:
_uvx=N/A,Sample
So we end up with two fields, each having two exceptions. Now that’s
very flexible!
Here are the views setup:
The Search Items view has the same Source as the Form, and the two fields that you need exceptions on. Both must have the Exact Match enabled. Title or description must contain _uvx to map the feature correctly between the two views.
What is nice with the KTL, is that you can re-use the same code over and over, and get tons of other cool features as a bonus.
You already have all the code - and it’s yours!
Everything is in the KTL.js file here: Knack-Toolkit-Library/KTL.js at master · cortexrd/Knack-Toolkit-Library (github.com)
I would love to be “super nice” and spend tens of hours reverse-engineering myself to extract only this feature’s code, but I think that I’ve been generous of my time already! Anyways… everything in the KTL is so tied-up in a monolithic package, that it would be a big waste of time to try to undo all this.
But still, if you’re interested in understanding how it works, it involves these functions:
- preprocessSubmit
- getFieldsKeywords
- parseKeywords
- processFieldsKeywords
- findRecordByValue
For about 150 lines of code total, just for the core of that feature. Hundreds more if you dig deeper into the functions.
Hope you like it,
Normand