Problem having a content dataset with a form dataset

Have two datasets on the same page… One pulls content (case studies and white papers) the other submits users who want to download the document (name, company, email, blah blah blah).

It’s a dynamic page for all of our documents, so #title (text element on the page) changes which comes form #dynamicDataset. I want to take #title.text and put it into the dataset #downloadDataset which writes the name, company, and email of the person wanting to download.

I can’t figure out how to take the #title.text and prep it into the #downloadDataset for when someone fills out the form, the title is put into the database collection. Right now, whole column is empty.

Use the setFieldValue() function. Something like this:

$w(“#downloadDataset”).setFieldValue(“title”, $w(“#title”).text);

I hope this is what you’re trying to accomplish,

Yisrael

That’s exactly what I’m trying to do… But here’s my issue in the console, I that dataset is write-only to log the customer. But I need a the #title.text to be logged with the form submission.

When I try to use .setFieldValue, I get this error:

FIRST ERROR MESSAGE:

  1. t {code: “DS_NOT_LOADED”, message: “The dataset didn’t load yet. You need to call setFieldValue inside the onReady for the dataset.”, name: “DatasetError”, stack: “DatasetError: The dataset didn’t load yet. You nee…es/santa-wix-code/dist/wixcode-worker.js:17:71718”, Symbol(error was handled): true}

  2. code:“DS_NOT_LOADED”

  3. Symbol(error was handled):true

  4. message:“The dataset didn’t load yet. You need to call setFieldValue inside the onReady for the dataset.”

  5. name:“DatasetError”

  6. stack:“DatasetError: The dataset didn’t load yet. You need to call setFieldValue inside the onReady for the dataset.↵ at C (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:111528)↵ at setFieldValue (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:85207)↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:3486)↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:53379)↵ at Object.u [as try] (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:169361)↵ at AppController.eval [as setFieldValue] (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:53358)↵ at https://f1ddab1d-f543-4da2-a1fb-3c570fc6ffa0.static.pub.wix-code.com/static/v2/02f44c57-d527-4d55-9dea-6c66539e2adf/f1ddab1d-f543-4da2-a1fb-3c570fc6ffa0/pages/mosim.js?empty-if-missing=true&exclude=wix-&module-name=mosim:35:26↵ at eval (https://static.parastorage.com/services/js-wixcode-sdk/1.233.0/lib/wix.min.js:1:94650)↵ at i (https://static.parastorage.com/services/js-wixcode-sdk/1.233.0/lib/wix.min.js:1:94797)↵ at eval (https://static.parastorage.com/services/js-wixcode-sdk/1.233.0/lib/wix.min.js:1:95117)↵ at Array.map ()↵ at l (https://static.parastorage.com/services/js-wixcode-sdk/1.233.0/lib/wix.min.js:1:95094)↵ at s (https://static.parastorage.com/services/js-wixcode-sdk/1.233.0/lib/wix.min.js:1:95705)↵ at e.value (https://static.parastorage.com/services/js-wixcode-sdk/1.233.0/lib/wix.min.js:1:323349)↵ at https://www.hcmi.co/_partials/santa/1.3927.23/node_modules/santa-wix-code/dist/wixcode-worker.js:17:71718

  7. proto:t
    ===========================================
    And then, when I put that into a .onReady… I get this error:

SECOND ERROR MESSAGE:

console.js:35 An error occurred in one of datasetReady callbacks

  1. t {code: “DS_NO_CURRENT_ITEM”, message: “There is no current item”, name: “DatasetError”, stack: “DatasetError: There is no current item↵ at I (h…/services/dbsm-viewer-app/1.264.0/app.js:6:57167)”, Symbol(error was handled): true}

  2. code:“DS_NO_CURRENT_ITEM”

  3. Symbol(error was handled):true

  4. message:“There is no current item”

  5. name:“DatasetError”

  6. stack:“DatasetError: There is no current item↵ at I (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:111703)↵ at setFieldValue (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:85255)↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:3486)↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:53379)↵ at Object.u [as try] (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:169361)↵ at AppController.eval [as setFieldValue] (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:1:53358)↵ at https://f1ddab1d-f543-4da2-a1fb-3c570fc6ffa0.static.pub.wix-code.com/static/v2/7a511946-f5d7-4150-979b-ed3713f063c9/f1ddab1d-f543-4da2-a1fb-3c570fc6ffa0/pages/mosim.js?empty-if-missing=true&exclude=wix-&module-name=mosim:36:27↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:3486)↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:98852)↵ at Array.map ()↵ at s (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:98807)↵ at fireEvent (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:99073)↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:63844)↵ at w (https://www.hcmi.co/_partials/santa/1.3927.23/node_modules/santa-wix-code/dist/wixcode-worker.js:17:134569)↵ at Generator._invoke (https://www.hcmi.co/_partials/santa/1.3927.23/node_modules/santa-wix-code/dist/wixcode-worker.js:17:134357)↵ at Generator.t.(anonymous function) [as next] (https://www.hcmi.co/_partials/santa/1.3927.23/node_modules/santa-wix-code/dist/wixcode-worker.js:17:134748)↵ at r (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:57073)↵ at eval (https://static.parastorage.com/services/dbsm-viewer-app/1.264.0/app.js:6:57167)”

  7. proto:t

Please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor.

It’s the Dynamic Page called “PapersAndCaseStudies”. I tried just putting the path in there now, but still having the dataset issue.

It’s really messy… I’m trying to just get it working, then I’m cleaning it up and will rebuild into a new dynamic page set.

$w("#downloadsDataset").setFieldValue("title", path);
$w("#downloadsDataset").onReady( () => {
      $w("#downloadsDataset").setFieldValue("title", path);
});

Some observations:

You have the setFieldValue() command twice. The first time is before the #downloadDataset’s onReady() and therefore results in an error.
Further, you want to retrieve a value from the #dynamicDataset. You can only retrieve that value when that dataset is ready.
The #dynanicDataset has a “current” item, however the #downloadDataset does not have a “current” item. You will need to filter based on the _id of the current item of the #dynamicDataset.
Once you have a current item in the #downloadDataset, then you can do the setFieldValue of the appropriate field in the #downloadDataset.

I hope this helps,

Yisrael

Correct… I was trying to slam that anywhere were it would work, to no effect. Thank you… The filter I never tried to apply to the current item out of dynamicDataset… Let me work with that. Thank you my friend. :slight_smile:

That’s not working at all.

I cannot set fields in a ‘pending’ recordset, any attempts to call this I get a “DS_NO_CURRENT_ITEM” for the #downloadDataset. I don’t see any way to get around this… It requires that I wait using .onReady, and once I do that it instantly tells me “DS_NO_CURRENT_ITEM”.

I tried to even use a hidden input field but just set the text to the title. Doesn’t work either. Once it’s tied to a dataset it just goes blank whatever I call to it.

I would suggest using the onReady of the #dynamicDataset, and doing a wix-data query (not using a dataset) of the collection. This way you can retrieve the record from the collection and use the desired field.

That I’m not having any issues with… This works great:

$w.onReady( function () {
$w(“#dynamicDataset”).onReady( () => {
let objPaper = $w(“#dynamicDataset”).getCurrentItem();
console.log(objPaper[“title”]);
});
});

So I now have an object of the currently loaded item and have direct access to all of it’s elements. This works and I see the correct title in the console. What I don’t know how to accomplish is what to set where to this {objPaper[“title”]} so it gets written into the db once the user selects “Request”.

Ok… I’m really close with this… Here is what I’ve done…

Added a drop-down box mapping the output side to the downloadDataset and the input fields from the dynamicDataset. This works. My plan is to hide this field and programmatically select the only name that comes up in the list.

But…

Yeah, that doesn’t work either. Sigh.

$w(“dbTitle”).value = itemObj[“title”];
$w(“dbTitle”).selectedIndex = 0;

Why don’t these work? The page loads and no change happens on the form:

$w.onReady( function () {
//TODO: write your page related code here…
$w(“#dynamicDataset”).onReady( () => {
let itemObj = $w(“#dynamicDataset”).getCurrentItem();
if (itemObj[“docType”] !== “White Papers”) {
$w(“#pageTitle”).show();
}
$w(“#dbTitle”).selectedIndex = 0;
});
});

On first glance, you don’t want this:
if (itemObj[“docType”] !== “White Papers”) {
You want this:
if (itemObj.docType !== “White Papers”) {

Ahhh… ok. Well that part works, but thank you, i’ll make that adjustment.

This is what doesn’t work: $w(" #dbTitle ").selectedIndex = 0;

To reset a dropdown , you need to set to undefined .
$w(“#dbTitle”).selectedIndex = undefined;

I don’t think you’re following me here.

The dropdown list is getting populated from the dynamic dataset’s “Title” text field, there is only 1 of those, thus it has the position of [0] within the dropdown. The dropdown’s submit output is going towards the DownloadDataset. This ‘would’ correct my whole issue.

Running the page with the dropdown visable this is what happens:

1.) Page loads
2.) Dropdown pulls in “The Real Title Of The Page” as selection [0] but ‘not’ selected.
3.) If I select “The Real Title Of The Page” in the drop down and submit the form, it works, as expected.

I need to be able to programmatically select this in the dropdown as the element will be hidden. That’s where I was trying the .selectedIndex[0]

Hey PJ,

I used my brain until I smelled smoke. Since the brain itself identifies smell, the whole experience proved to be recursive. Ummm, I’ve got a headache.

OK, so it’s like this. Well, I’ll tell ya’ - my brain is so fried I’m not even sure I can explain this. Here’s what I ended up for the onReady() function:

$w.onReady(function () {
  $w("#dynamicDataset").onReady(() => {
    let itemObj = $w("#dynamicDataset").getCurrentItem();
    if (itemObj.docType !== "White Papers") {
      $w("#pageTitle").show();
    }
    $w("#downloadsDataset").new()
    .then(() => {
      console.log("New item created");
      $w("#downloadsDataset").setFieldValue("title", itemObj.title);
    })
    .catch((err) => {
      let errMsg = err;
    });
  });
});

I tried this and it works. Hopefully it works the way you want. The “secret sauce” is the dataset’s new() function which creates an item in the dataset to hold the user entered information and ultimately to be saved to the collection.

I really hope this is what you’re looking for. I’m running out of aspirin.

Yisrael

You are amazing… Let me try that out. Thank you :slight_smile: