Form submission problem

Hi,
I have created a form to populate a database. All fields are mandatory.
I also created a Submit button.

If I leave the fields blank (no entry/blank), the form gets submitted even if mandatory fields are empty and it get posted in the database.

How can I validate the form has the mandatory fields filled before submitting?

Thank you!

Pierre Lacasse

Can someone help me with this?

Pierre, are you quite sure that the empty row is actually written to the collection? Have you checked a time stamp? Because it seems odd to me: when there is no user input, onItemValuesChanged() is never called and a visual Save actually does not save anything.
If you want to prevent this visual Save-that-is-not-really-a-save, just put a global boolean in, set it to true in the onItemValuesChanged and enable/disable your save-button according the state of that boolean.

Gir, I am a beginner in coding with Wix Code.
Can you help me with the Bolean code to enter?

Thank you

Pierre

Do this:

1: I assume you have the standard wix Save button attached to the dataset. Delete this button, put in a standard button (we call it button1, or whatever), open the Properties Panel, uncheck “Enabled by default” and on the onCLick event, add a handler, which we will call button1_click. Now Wix will insert a function called “export function button1_click ,”, see below.
2 ; make sure the follwing code is on your page

$w.onReady( function () {

// make sure your dataset is called dataset1
$w(“#dataset1”).onReady(() => {
$w(“#dataset1”).onItemValuesChanged((itemBeforeChange, updatedItem) => {
$w(“#button1”).enable();
});
});
});

export function button1_click(event, $w) {
$w(“#dataset1”).save();
}

What is does is that only when a user has changed any field, the Save button will be enabled, else not.
That should do it, forget about the boolean. Good luck.

THank you Gir,
I think this will do the trick but this is a Login form and when a user is already in the Db, it will pull the data so he can verify if everything is accurate and populates the fields. At this point, there will not be any changes to the form, how can we handle this and have it save anyway in this specific case?

Hi Giri, me againi,
I tried to implement the code you suggested me.

My Db is named ListeMembres. So I changed dataset1 for ListeMembres.

This Db is active but I get an error (red dot) beside every lines I enter ListeMembres.

Here is my code:

$w.onReady( function () {

Red dot $w(“#ListeMembres”).onReady(() => {
Red dot $w(“#ListeMembres”).onItemValuesChanged((itemBeforeChange, updatedItem) => {
$w(“#button1”).enable();
});
});
});

export function button1_click(event, $w) {
Red dot $w(“#ListeMembres”).save();
}

What am I doing wrong?

Giri,
the dataset1 you are using is the dataset of the Database where the data is stored. If it is this, in my case it is called ListeMembres.

Thank you

Pierre Lacasse

Pierre, they are 2 different things: a Collection might be called " ListeMembres " in the database, but once you use a dataset (which I assume you are doing, that icon on a page that says ‘dataset’, Wix allows you to give a name to the result of the query and use it on a page. Wix normally names it “dataset n” or “dynamicDataset n”.
If you use a dataset, you must refer to it in code, when handling this queryresult, by it´s dataset name, not by its collection name.
If, on the other hand, you do not use a dataset and use, in code, wix-data to do a query in code, then you would use the var that you assigned to it in code, like “objResultSet” or whatever and address is thru that handle.
So, in our case, check if you have a dataset on your page, goto Properties, checj its name and use that in code.

Giri,
I thought of it but was entering DynanicDataset instead of dynamicDataset. Now the red dots are gone.
I will test further.

I had asked you another question prior of this one.

Previous post
Thank you Giri,
I think this will do the trick but this is a Login form and when a user is already in the Db, it will pull the data into the form so the member can verify if everything is accurate. If he doesn’t change anything he will click the button to save. At this point, there will not be any changes to the form, how can we handle this and have it save anyway in this specific case?

Pierre Lacasse

Pierre, in this case, when a user has not changed anything, we set it up that the save button is disabled, so they cannot click it, which is exactly what we want, because there are no changes to save.

Giri,
fine but by clicking this save button, I wanted the user to access the other part of my site since he is already registered.and has the rights to get to the site.

I can create another button (let say “Go to site” that will only show if the form hasn’t changed but for a new user, I want him to fille the form to gather his personal informations

In that case, to keep the user interface comprehensible, I would suggest doing it like this:

A: User does not exist: show empty form and at the bottom show a button with “Save and continue”, with the same logic as described before (button disabled if nothing filled out, enabled when it is)
B: user does exist: show existing information, put a text at the top of the formm saying something like “Update your information if necessary” and at the bottom an enabled “Continue >” button. Once they did change anything (same logic), change the button text to “Save and continue”.

Giri,
Thank you very much for your appreciated help.

Again, I am not an experienced coder.

Would it be to much asking me how you would code this…

Thank you!

Pierre Lacasse

Hi,
I have a web page with a dataset for a input form.

There are 5 fields that the user has to input.and populate the Main databse ListeMembres

Now, I have it working so if there is no change to the form, the Save button is Disable.

I have another situation where if a membre log in and he is on the Database, he has nothing to change on his profile then my Save button is still disable.

I would like to check my form fields to find out if any are left blank then keep the Save button disable otherwise enable it only if all field are not empoty.

I have this code in test to find if the a field is empty then pout a message on the ocnsole.log if not put a different message on the consiole.log

I get an error on the export function line
PARSING ERROR: Import & Export may only appear at the top level

Can someone help me!
Thank you

Pierre

// For full API documentation, including code examples, visit http://wix.to/94BuAAs
$w.onReady( function () {
$w(“#button1”).disable();
$w(“#dynamicDataset”).onReady(() => {
$w(“#dynamicDataset”).onItemValuesChanged((itemBeforeChange, updatedItem) => {
$w(“#button1”).enable();

ERROR export function button1_click(event, $w) {
if (“input7”.length === 0) {
console.log (“SVP entrez nom de famille”);
}
else {
console.log (“OK”);
}
$w(“#dynamicDataset”).save();
}