I am trying to create a form that each member can submit. Also, when the member returns to the form, it should still display the data from their last input. Basically, a form that the user can update.
here is my code currently:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixData from 'wix-data'
// Auto-Fill Form
$w.onReady(function () {
$w("#input1").value = $w('#dataset1').getCurrentItem().firstName;
$w("#input2").value = $w('#dataset1').getCurrentItem().lastName;
$w("#input3").value = $w('#dataset1').getCurrentItem().email;
$w("#input4").value = $w('#dataset1').getCurrentItem().list1;
$w("#input5").value = $w('#dataset1').getCurrentItem().list2;
$w("#input6").value = $w('#dataset1').getCurrentItem().list3;
});
// Submit Auto-Filled Items
export function Submit_click(event, $w) {
$w('#dataset1').setFieldValue('fname', $w('#input1').value);
$w('#dataset1').setFieldValue('lname', $w('#input2').value);
$w('#dataset1').setFieldValue('email', $w('#input3').value);
$w('#dataset1').setFieldValue('list1', $w('#input4').value);
$w('#dataset1').setFieldValue('list2', $w('#input5').value);
$w('#dataset1').setFieldValue('list1', $w('#input6').value);
}
![](https://static.wixstatic.com/media/a27d24_e4adb0c1fdc74405b2dd1f4b5df9b0d1~mv2_d_2164_1256_s_2.png/v1/fill/w_49,h_28,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_e4adb0c1fdc74405b2dd1f4b5df9b0d1~mv2_d_2164_1256_s_2.png)
#members #autofill #form #updateform #getCurrentitem #getCurrent
i currently have a filter on my dataset for logged in user. that is why i am trying to create code to display the inputs as blank if this is the first time the user is filling out the form. otherwise, with the filter you won;t be able to input anything because there is no data for the logged in user yet
import wixLocation from 'wix-location'; import wixUsers from 'wix-users'; import wixData from 'wix-data' $w.onReady(function () { //check the current user's email using getEmail() let user = wixUsers.currentUser; user.getEmail() .then( (email) => { let userEmail = email; // "user@something.com" } ); //query the mylist dataset wixData.query("mylist") .eq("email") .find() .then( (results) => { //if the dataset does NOT have the email, then make the inputs fields blank since this is their first time submitting if(userEmail NOT "email"){ $w('#input1').value = undefined $w('#input2').value = undefined $w('#input3').value = undefined $w('#input4').value = undefined $w('#input5').value = undefined $w('#input6').value = undefined } } ) .catch( (err) => { let errorMsg = err; } );
or at least the user id for the form is already stored
this is helpful, but i need to be able to have the form blank when a user sees the form for the first time, but then populated after they fill out some boxes. that link assumes the data is already stored when they reach the form
Something similar for members profile page is already setup in a Wix tutorial. Have a look and use the code as a starting point.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area