Unique Item Reference Code for Collection Items
Learn how to create a unique reference code as items are inserted into a collection using Corvid (a.k.a. Wix Code). Unique reference numbers are an easy way for you or your website users to search or locate a specific item in your collection.
This example allows you to add shapes to a collection called #Shapes, automatically allocating each new shape a unique reference code of the format REF0#. Try the example below.
#btnAddShape
Try it!
#iptShape
#txtMessage
Select a shape to add to the collection
#repShapes
Square
Rectangle
Circle
Triangle
Triangle
Square
When the button #btnAddShape is clicked, a query is executed directly on the #Shapes collection to find the reference code of the most recent shape entered. If the collection is empty to start with, then the new shape is inserted with a reference code of REF01. If the collection already contains shapes, the reference code of the most recent shape is taken and iterated by 1 before inserting the new shape into the collection. Once the new shape has been inserted, the repeater displaying the collection refreshes.
Page Code