Custom Message Displayed with form error!

Withe amazing help of the Wix Code team, I was able to prevent duplicated submissions into my database.

Now i need some help displaying an error message when an error occurs

1 Like

Hi,
A simple solution might be to add a text component to your page, set it to hidden by default and change it to visible on dataset error so the user sees the message only when an error occur.

Does this require any coding in the image I referenced above?

Can you guide me with the specific steps on this?

Assuming you added a text component for the error message called errorText, you can:

  1. Set it to “Hidden on load” using the component property panel
  2. In the block of code dataset1_onError you can add the line $w('#errorText').show()

How exactly do I add the ‘errorText’

And i get an error with this code:

I have a few questions:

Assuming I start from step 1:

1.) I’m adding a text element to be displayed on dataset error.

2.) How do I correct add a text component for the error message called errorText, you can2.) How do I program this to display only on error?

in this code: dataset1_onError you can add the line $w('#errorText').show()

What do I insert where it says: you can add the line

Detailed steps:

  1. Add a text component, set its text
  2. In the properties panel, change the ID to “errorText”
  3. In the properties panel, set it to “hidden on load” (as you already did)
  4. In the page code, inside the function dataset1_onError (line 8 in the code you took a screenshot of) add the following:
    $w(’ #errorText ').show();

That’s it. You should be good to go :slight_smile:

Thanks

One last question :slight_smile: What’s the reason for this error

Also - This text should only pop up when the database finds duplicate entries. Look:

Any parameters that are declared and not used later prompt this warning. In your case, the ‘event’ parameter is declared automatically as it includes some info about the specific message that occurred (see wix-dataset - Velo API Reference - Wix.com for details). If you have no use for it, you can simply omit it, if you’d like.

The prompt only needs to show when dups are found. Error message is not needed since the fields all become red when validation errors are found.

In this case, you need the event param.
Check whether the error.message equals the error message you generate in case of duplication (in your example: “count is more than 0, dups found!”) and only in this case, display the error text.

So your text might look something like that:

if(error.message === 'count is more than 0, dups found!') {
    $w('#errorText').show();
}

So, if(error.message === ‘count is more than 0, dups found!’) { $w(‘#errorText’).show(); } needs to be inserted on line 8 of my code for my hidden property?

I know I have a unique request. This request amends some of the steps you mentioned above. Perhaps, we can schedule a call, just so I can learn how to amend the code properly on my own.

I think I need a few changes done.

on line 9.
I’ll see what can be arranged regarding the call you requested. Will be in touch with you in the beginning of the week.

Thanks so Much!

I appreciate this so much

I need help on the same issue. Can someone please help me too? Thanks