Hey dudes, I’m a poor beginner when it comes to coding maybe someone can help me. I have created a member area with a form where members can provide their data. This will be stored in a dataset. For the first time when the member visit the page he needs to click a Button (saying: create new dataset item) This one I would like to do automatically by code. Can’t be so complicate but I don’t know how.
BTW when member is coming back after editing he is automatically connected to his edit because the dataset settings say. (Owner=Loged-In User)
For my usage It is important that only for the first time a member is opening the page a new dataset item will be created.
Can someone help with that?
- This will be stored in a dataset.
Nothing will be stored in a → DATASET!
Your data will be stored inside a → DATABASE (collection).
The → DATASET is just some kind of connection, which connects the DATABASE, with all other elements on your page! Do not mix it up, it will befog your thoughts about how it realy works.
- BTW when member is coming back after editing he is automatically connected to his edit because the dataset settings say. (Owner=Loged-In User)
For my usage It is important that only for the first time a member is opening the page a new dataset item will be created.
To achieve your wished functionality, i think you will have much more coding work, then you expect!
- Get current logged-in-user data
- Take a look onto your DATABASE for an already existing ENTRY of the current logged-in user.
- If not, create a new entry.
- If already existing do not show-up the form again.
You already have prepared your database and structured it?
The most important will be the DATABASE and its, structure!
Do not start with coding, if your database is not ready yet!
Hey Velo-Ninja, thanks for your kind answer.
Yes, all works well. The database and dataset I mixed up you are right. Everything works great. There is only the problem with creating a new entry. Also showing up the form again is wanted and already working. Via this way the member can edit or delete his entry. All tested and all works well.
The only problem with my button solution is that members can create more than one dataset entry and this is not wanted. I have created a little code saying that when one mandatory field in the form is empty the button is enabled. This means that the button is disabled when a item has already saved.
export function button2_viewportEnter ( event ) {
if ( $w ( “#dropdown1” ). value == “” ){
$w ( “#button2” ). enable ();
}
}
I think this is not the moast smartest solution.
If your approach is sufficient for your needs and it works for you → than you have found your solution.
Surely you will also have some elements which are connected trough → DATASET-CONNECTION in the → PROPERTY-PANEL, i do not know about.
So giving you any further advice, could be wrong. So if it works for you, let it as it is right now.
There is still a problem. when I save the form the button is still active and the user could create more items into the database. Only after refreshing the page the button is disabled as needed. Have you an idea how to engage that?
Yes of course, there is a form with many fields saved in the database. But is that important when focus is creating complete new items?
I have now created a new little code to disable the button who creates a new database item. But when I select from the other drop-downs the disabling disappears. Does anybody knows how to deal right with that?
This is the code I’m using so fare:
import wixData from ‘wix-data’ ;
$w ( '#dropdown1' ). onChange ( **function** () {
$w ( "#button2" ). disable ();
}
)
To deal right with that, i would suggest you to disconnect all elements on your page from dataset, and connect every single element with code.
This way you won’t mix up automatic functions (which are included in the dataset-connections inside PROPERTY-PANEL), with your code generated ones.
What you are doing right now → is just jumping from one corner to another trying to fix issues with bad workarounds.
- Make a little → RESET
- Do some → BRAINSTORMING and try to imagine, how you want your functions to be working.
- Take a paper and write down all single steps, which should be done.
- Start coding all single steps —> one by one, until you got your wished endresult.
- Do not mix up code and dataset-connections between page-elements and dataset in the Property-Panel.
Doing it the → CODING way, will open you much more functions and features, which you can generate like you want and at the end you get much more flexibility.
I get what you are saying. But everything really works great only with the exeaption that multiple items per user can be created and I want to proceed. But anyway, thanks for your feedback