Custom cms form

hi there

I’m building a custom form and I’m using custom code to autofill an input field. i attached the input field to a database so when the form submits the values of the form gets saved. everything gets saved and the input field gets filled but the value is not getting in to the database while the console log show the correct value.

import wixLocation from 'wix-location';

$w.onReady(function () {
    // Get URL and parse query parameters manually
    const url = wixLocation.url;
    const query = wixLocation.query;

    // Populate input fields from URL query parameters
    if (query && query.Fname) {
        $w("#firstname").value = query.Fname;
    }
    if (query && query.Lname) {
        $w("#lastname").value = query.Lname;
    }
    if (query && query.ID) {
        $w("#Odoo-id").value = query.ID;
    }

    // Select all buttons in the repeater
    $w("#repeater1").onItemReady(($item, itemData, index) => {
        // Attach an event handler to each button
        $item("#ask-quote").onClick(() => {
            // Get the name and email of the selected partner
            const selectedPartnerName = itemData.title; // Assuming 'title' is the field containing partner names
            const selectedPartnerEmail = itemData.email; // Assuming 'email' is the field containing partner emails

            // Set the field value to match the selected partner name
            $w("#Installer").value = selectedPartnerName;

            // Populate the #partner-email field with the selected partner email
            $w("#partner-email").value = selectedPartnerEmail;

            console.log(selectedPartnerEmail);

            // Scroll to the section if needed
            $w('#ask-quote-box').scrollTo();
        });
    });

    // Reset dropdownPartner when areaDropdown is changed
    $w("#areaDropdown").onChange(() => {
        // Reset Installer to default or empty value
        $w("#Installer").value = "";
        // Reset Partneremail to default or empty value
        $w("#partner-email").value = "";
    });
});

it looks like when i click the submit button the value gets reset, its a wild guess

ALWAYS THE SAME OLD ISSUES!!!

  1. Did you use a DATASET ? → NO NEED TO ANSWER → YOU HAVE USED A DATASET!

The way you are working → it never will work the right way. You should know, that mixing a DATASET with CUSTOM based CODE → you always will get troubles.

Why?

Because the DATASET has it’s → OWN PROCESS-FLOW
It won’t wait for code, as long as you did not setup everything the right way and used HOOKS.

Your DATASET-PROCESS and your CODE now working simultaniously (not ASYNCHRONE) not waiting for each other. This is why you see the correct DATA in your LOG —> but inside your DATABASE → nothing happens.

You should know, that as soon as you are dealing with DATASETs → your first 2-CODELINES always should be —>

$w.onReady(()=> {console.log('Page is ready.');
    $w('#dataset1').onReady(()=> {console.log('Dataset is ready.');
        //PASTE ALL YOUR OTHER CODE HERE....
        //PASTE ALL YOUR OTHER CODE HERE....
        //PASTE ALL YOUR OTHER CODE HERE....
        //PASTE ALL YOUR OTHER CODE HERE....
        //PASTE ALL YOUR OTHER CODE HERE....
        //PASTE ALL YOUR OTHER CODE HERE....
        //PASTE ALL YOUR OTHER CODE HERE....
    });
});

This was just one of few correction-steps you will have to do.

  1. The second one would be to use one of the DATASET’S HOOKs…
    You can use the onBeforeSave()-HOOK, to manage the data, before the DATASET, saves the data to your database.

This is called a HOOK → (somekind of option, where you can INJECT DATA by your own to the automatic PROCESS-FLOW of the DATASET). You remember → the DATASET do not wait for your CODE!!!
But using the HOOK → you tell the DATASET → to wait for your DATA-MODIFICATIONS !!!

The rest will be on your own → GOOD LUCK !