Site: cosworthvega.com
Page: cv-history-registry (dynamic page)
This page is activated when viewing a car’s details lightbox (Registry Car Details and clicking on test (onClick function, not a link).
The items ARE NOT being retrieved from the database and am getting the following error in browser Developer Tools panel.
Here is my code:
import wixData from ‘wix-data’;
import {local, session} from ‘wix-storage’;
$w.onReady( function () {
//TODO: write your page related code here…
let CarId = session.getItem(“CarId”,CarId);
$w(“#headerDash”).text = CarId;
$w(“#dynamicDataset”).onReady( () => {
console.log(“The dataset is ready”);
$w(“#repeater1”).onItemReady( ($w) => {
wixData.query(‘CV-History-Registry’)
.eq(“dash_no”, CarId)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
$w(‘#date’).text = res.entry_date;
$w(‘#content’).text = res.content; // ditto…
console.log($w(‘#date’).text);
console.log($w(‘#content’).text);
let currentItem = $w(“#dynamicDataset”).getCurrentItem();
console.log(currentItem);
// Defensive programming helps prevent unexpected side effects!
if (!currentItem.hasOwnProperty(‘entry_date’) || currentItem.entry_date !== $w(‘#date’).text)
{
// We have a problem with the filtered result this is a problem so lets throw and error
// for our catch below
throw Error(‘filter failed’);
}
});
});
});
});
I NEVER get the console log saying dataset is ready?
I got that same error of the ‘unconfigured dataset’ and the problem was that the dataset wasn’t ready (even thought it was inside the onReady of the dataset). what I could understand was that the dataset was unconfigured because it was empty like if it haven’t loaded yet. at the end I solved the issue putting the code that was giving me the error inside the " .then " of my dataset filter and it worked.
hope this helps you.
Fogan, I have another program that lists ALL the entries in a Repeater and it works just fine. My database contains 390 entries. Verifed Sandbox AND Live. Has been synced and tested on live site.
This program uses a filter to ONLY retrieve the entries matching CarID passed in as a session variable. You can clearly see that the CarID is known because it is displayed in the page header.
Added: $w(" #repeater1 ").onItemReady
See updated code block above. NO CHANGE! SAME PROBLEM!!
I have rewritten the code to use a Filtered Approach instead of a DB Query. EITHER APPROACH gives SAME RESULT… operation not allowed on unconfigured dataset. WTF???
Here is new code block… I can toggle one or the other versions on/off my moving /* – */.
import wixData from ‘wix-data’;
import {local, session} from ‘wix-storage’;
$w.onReady(function () {
let CarId = session.getItem(“CarId”,CarId);
$w(“#headerDash”).text = CarId;
$w(“#dynamicDataset”).onReady( () => {
console.log(“The dataset is ready”);
$w(“#repeater1”).onItemReady( ($w) => {
wixData.query(‘CV-History-Registry’)
.eq(“dash_no”, CarId)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
const originalDate = $w(“#date”).text;
console.log(‘originalDate: ’ + originalDate);
const newDate = originalDate.split(’ ‘).splice(0, 4).join(’ ‘);
$w(’#date’).text = newDate;
console.log('Time removed from Date/Time Stamp: New Date ’ + newDate);
$w(“#origDate”).hide();
let currentItem = $w(“#dynamicDataset”).getCurrentItem();
console.log(currentItem);
});
});
});
});
/*
// FILTER APPROACH…
$w.onReady(function () {
//TODO: write your page related code here…
let CarId = session.getItem(“CarId”,CarId);
$w(“#headerDash”).text = CarId;
$w(“#dynamicDataset”).onReady( () => {
console.log(“The dataset is ready”);
$w(“#dynamicDataset”).setFilter(wixData.filter()
.eq(“Dash_no”,CarId)
).then(() => {
$w(“#repeater1”).show();
const originalDate = $w(“#date”).text;
console.log(‘originalDate: ’ + originalDate);
const newDate = originalDate.split(’ ‘).splice(0, 4).join(’ ‘);
$w(’#date’).text = newDate;
console.log('Time removed from Date/Time Stamp: New Date ’ + newDate);
$w(“#origDate”).hide();
let currentItem = $w(“#dynamicDataset”).getCurrentItem();
});
});
});
*/
FYI - PROBLEM SOLVED.
On a hunch, since the original page that this page was based upon was NOT a dynamic page. I deleted this dynamic page and started over. Using the LIST ALL page as a basis, I simply added the dataset query method matching dash_no as passed in from the session variable. It is working now as expected.
Beats the hell out of me as to why I had SO much trouble with this an NO ONE could offer a solution???
I guess one of these days I will figure out when to use a Dynamic dataset vs a regular Dataset!!
I’m glad that you could solve your problem and now is working as expected. it was a weird issue, and now that you talk about the dynamic datasets and the regular dataset let me tell you that they are a little buggy in some situations: sometime you can’t have a dynamic and a normal dataset connected to the same collection because doesn’t work properly, and rigth now I’m having an mistery problem with a dynamic dataset that filters using the dataset menu, but when you try to filter it by code it filters the items but doesn’t update the pages, when you change to another dynamic page stays in the same. (in this case is where I was getting the same error as you). I hope that wix solve this problems soon, so life can be a little bit less frustrating when using wix code.