Is it possible to create a 6 digit Unique Id with Custom JS and set to hidden field to send data on submit form?

  • Issue description:
    Dear Forum Community,

I’m currently exploring the possibility of incorporating a 6-digit unique ID generation process into my web forms using custom JavaScript. My aim is to enhance data management and streamline form submissions on my website. I’m particularly interested in understanding the technical aspects involved in dynamically creating such IDs and how they can be seamlessly integrated into the form submission process.

Could anyone shed some light on the best practices and potential challenges associated with this approach? Any insights, tips, or examples from your experience would be greatly appreciated. Additionally, if you have any alternative methods or suggestions for achieving similar functionality, I’m open to exploring those as well.

Thank you in advance for your valuable contributions!

2 Likes

Hi Leo, and welcome to the Forum. Hang in there. This is a great question and I’m sure the Staff will be able to help you once they get from their weekend.

Hey there @Leo_Serres :wave:

Sure, our devs have come up with a custom code that should be added to the Custom JS field:

const FIELD_ID = '[total]';

const uniqueID = () => Math.random().toString(36).substring(2, 8);

widget.setFieldValue(FIELD_ID, uniqueID());

Do not forget to replace the FIELD_ID in the 3rd line of the code with the actual ID of your Hidden field:

image


Check it out and let me know how it worked :slightly_smiling_face: