I added the Wix default Job Items, Item tempalte.
I added a Wix Form on the item.
There is a field “job_id” on the form.
I want to get the job id when a user submission the job apply form.
I have tried bwlow,
$w.onReady(function () {
// Get the current dynamic page's item from the dataset
const jobId = $w('#Jobs').getCurrentItem()._id; // Replace 'dataset1' with your actual dataset ID
// If you have a form field with the ID 'jobIdField' (hidden field for job ID)
$w('#job_id').value = jobId; // Set the job ID in the hidden field
// Optionally, log the job ID for debugging purposes
console.log("Job ID set to form:", jobId);
});
it says .getCurrentItem is not a function
So I try
$w.onReady(function () {
// Wait for the dataset to load before accessing the current item
$w('#Jobs').onReady(() => {
// Now that the dataset is ready, retrieve the current item
const currentItem = $w('#Jobs').getCurrentItem();
// Check if the current item exists, then set the job ID
if (currentItem && currentItem._id) {
const jobId = currentItem._id;
// Set the job ID in the hidden form field
$w('#job_id').value = jobId;
// Optionally log the job ID for debugging
console.log("Job ID set to form:", jobId);
} else {
console.log("No job item found.");
}
});
});
it says TypeError: $w(…).onReady is not a function
I am very tired… Just want to geta ID. But spend hours have no solution…
$w.onReady(() => {
// Ensure the dataset is properly connected to the page
const dynamicDataset = $w('#Jobs'); // Replace '#Jobs' with the correct ID of your dataset
// Wait for the dataset to load
dynamicDataset.onReady(() => {
// Get the current item from the dataset
const currentItem = dynamicDataset.getCurrentItem();
if (currentItem && currentItem._id) {
const jobId = currentItem._id; // Retrieve the job ID from the current item
$w('#job_id').value = jobId; // Replace '#job_id' with your form field ID
console.log("Job ID set to form:", jobId); // Debugging: Check if the ID is set
} else {
console.error("No job item found.");
}
});
});
The dynamic page data is accessed using the dynamic dataset connected to the page.
Ensure that the dataset is properly set up and connected to the relevant collection.
Use the getCurrentItem() method on the dataset, but only after it is ready.
I see the problem. You’re trying to get current item’s id auto generated when submitted. But what I see is you’re using the form element and not the Wix input elements. You need to make this using Wix input elements or replace the jobs element with the current dataset element available in your form page (you have to add the dataset from CMS tab)
And I guess you can remove the job_id element since I think it’s random id generation field and add some math.floor or math.random method.
This is my code
I use this way to send member ID to the webhook. And I need to pass the job ID to the webhook as well. This is really important to create relationship on my airtable record