URGENT! textbox not saved

hi
i have a textbox with value in it by default. the user do not see it or click it or change it.
i want this value to be saved in the database.
it is no saved.
i tried to focus the textbox but no help.
only if i click on the textbox then it will be saved. but i dont want the user to click it or even see it.

any help please?

If you have the default value set as initial text and not just placeholder and also connected that to the dataset accordingly the value should be saved. You don’t have to focus on it but it has to be connected to the dataset if you use dataset.

The value is not default. Its set by code.
The code calculate a string and puts it in the textbox. The textbox is connected to the database but is not saved. Only if i click on it manually then it saved.

Martin:
Can you help the community out by providing some context so they can help you?
If you share the code you are using, if any, that would be helpful.

Most importantly if you can share the URL of the page you are having problems with that will help folks see your problem and be able to offer help.

Cheers

Hi,
If an element is connected to a dataset, setting the element’s value in code does not set the value of the connected field in the dataset. That means if you use the dataset to perform a submit, the value changed in code is not reflected in the submitted item.
To submit the new value using a dataset, set the field’s value using the setFieldValue() function before performing the submit.
check out the API here .

Good luck :slight_smile:
Or

Thanks or.
I have managed this by code.
I have more urgent issue now with exporting the dataset as csv or excel file to the user.
I need an example of the code and library to do it.
Please help.

@martinshn Check out this article about exporting data from a collection using code.

Thanks, but i need more than 1000 items and i need that as a file and not as json string to use with another online tool.

Hi Martin
If you have some coding skills then the way to do this is to create a dynamic download button in an html component. Here is the HTML template code courtesy of stack overflow

<html>
<body>
    <button onclick='download_file("my_file.txt", dynamic_text())'>Download</button>
    <script>
    function dynamic_text() {
        return "create your dynamic text here";
    }

    function download_file(name, contents, mime_type) {
        mime_type = mime_type || "text/plain";

        var blob = new Blob([contents], {type: mime_type});

        var dlink = document.createElement('a');
        dlink.download = name;
        dlink.href = window.URL.createObjectURL(blob);
        dlink.onclick = function(e) {
            // revokeObjectURL needs a delay to work properly
            var that = this;
            setTimeout(function() {
                window.URL.revokeObjectURL(that.href);
            }, 1500);
        };

        dlink.click();
        dlink.remove();
    }
    </script>
</body>
</html>

To make this work you will need to create a simple messaging process between the htmlComponent and the page code as described in this article

Then if you take the suggestion from Or on how to extract and format the dataset info you can create any format of download. For example you can take the JSON created in Or’s link send it in a message to the HTML Component. In the HTML Component you can convert the HTML to a Comma Separated Values file using the example from this Stack Overflow Post:

Will you be able to try this out?

Steve

I will try. But how can i override the 1000 limit when i export the data to json? My data will have around 20000 rows.

Hi Martin
The documentation that Or referenced says this

The maximum allowable limit is 1000. So if you want to export more than 1000 items from your collection, you will need to perform multiple queries.

The reason is that a large query can take a long time. So you might want to display a progress display showing how much data has been processed after each read cycle.

So you will do approximately 20 reads.

When you call the query function the result you get back is an object defined by WixDataQueryResult in the documentation.

This object includes helper methods for large queries. One such method is next() which you use to read the subsequent 1000 records.

You can loop through by checking hasNext(). If it returns true then you have more to read. False then you have read all records.

You can check how many records were returned in the read by checking the length property.

That should help.

Steve

Wow steve. You are the best. I looked for help around 3 weeks all over and you are the first to really help me. Thanks a lot. Im going to try this out and let you know the results.

ok so i have tried this… i think im on the right way. but a small question…
in the link you gave me to the function that converts json to csv, there are 2 dependencies.
how to i install or use or call them so the function will work?

Hi Martin - what have you managed to do so far? The JSON to csv conversion code would be in a script that is loaded into the html component. When the data to download is sent to the htmlComponent as json you can run the converter before executing the download capability.

Can you post a link to the page you are working on?

The site is not published yet.

There is an html component that get the string and downloads it as csv file. But it needs to get csv string.
The code to convert json to csv uses 2 external files (underscore.js and moments.js) and i dont know how to use them in my code.

I managed to loop and build the json string.
If i will succeed to convert it to csv i think im done with my request successfully.

@martinshn Hey there. This was a sufficiently interesting problem that I have decided to create a stand alone post to show how to do this. Check out the post here:

Steve