Creating unique codes on the fly and validating after submit

I had a problem where my client wanted expression of interests to be submitted based on the submission code and the user email. Setting the email as unique did not work because they were then prevented from sending a different submission. So what I did was capture the submit process to generate a unique code based on two fields (submission code and user email) this goes into a short text field that is set as unique. When the user submits it copies the two fields (combined) into the unique field and an error us presented if that combination already exists. I jnow KTL have a libray for this but I find this easier to implement and can be read by any knack coder.

** This does not work with connections, multiple choice etc just short text. If anyone knows how to assign values from these fields to a variable let me know :slight_smile:
$(document).on('knack-view-render.view_X, function(event, view, data) {
var a

$(“#view_9 .kn-button”).on(“click”, function() {
// If this value already exists then prevent submission
var a = “”;
a = $(‘#field_’).val() //email field
b = $(‘#field_x’).val()// eoi code
c= a + b // make unique data
$(‘#field_a’).val(c) // field with unique set as must

})

});

Hope someone finds it useful

Modified the code to include connections and multiple choice

$(document).on(‘knack-view-render.view_X’, function(event, view, data) {
var click = 0 // ensure that the submit button event cannot be pressed again if the error concerning unique record appears.
$(‘#view_X-field_X’).change(function () {
$(‘#field_612’).val($(this).val())
click = 0
});

$(‘#view_X .kn-button’).on(‘click’, function() {
click = click + 1

// If this value already exists then prevent submission
if (click < 2) {
var a = ‘’
a = $(‘#field_Y’).val() + $(‘#field_4’).val()
$(‘#field_Y’).val(a) // field with unique set as must

}
})

});