Please, I need help with this - is it a bug?


As you can see the ‘collapsed on load button’ is checked …

Here the ‘collapsed on load button’ is not. This affects the tablet version too.
The only way i could fix it was to disable the mobile optimization (which i didn’t really want to do) but in so doing, the table view worked fine??

Also, whilst I have the ear of you marvellous people - can you put me out of my misery with this code query … PLEASE …

I have created a dropdown box for types of vendor and another field input box for zip code - how do I make the latter NOT accept being left blank?

Thanks so much … here’s the code …


import wixData from ‘wix-data’;

//For full API documentation, including code examples visit Velo API Reference - Wix.com

$w.onReady(function () {
//TODO: import wixData from ‘wix-data’;
});

export function searchButton_onClick() {
wixData.query(‘Tradesmen’)
.contains(‘title’, $w(‘#iAllTraders’).value)
.contains(‘postCode’, $w(‘#iPostCode’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
if($w(“#table1”).collapsed) {
$w(“#table1”).expand();
}
else {
$w(“#table1”).collapse();
}

}); 

}

$w.onReady(function () {
$w(“#table1”).columns = [
{
“id”: “col1”,
“dataPath”: “image”,
“label”: “Photo I.D.”,
“width”: 100,
“visible”: true,
“type”: “image”
} ,
{
“id”: “col2”,
“dataPath”: “company”,
“label”: “Company”,
“width”: 120,
“visible”: true,
“type”: “text”
},
{
“id”: “col3”,
“dataPath”: “phone”,
“label”: “Phone #”,
“width”: 75,
“visible”: true,
“type”: “text”
},
{
“id”: “col4”,
“dataPath”: “web”,
“label”: “Website”,
“width”: 100,
“visible”: true,
“type”: “url”,
“linkPath”: “url”
} ,
];
});

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w(“#button4”).label = “Logout”;
$w(“#button5”).show();
}
else {
$w(“#button4”).label = “Login”;
$w(“#button5”).hide();
}
} );

export function button4_onclick() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button4”).label = “Login”;
$w(“#button5”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in  
wixUsers.promptLogin( {"mode": "login"} ) 
  .then( (user) => { 
    userId = user.id; 
    return user.getEmail(); 
  } ) 
  .then( (email) => { 
    // check if there is an item for the user in the collection 
    userEmail = email; 
    return wixData.query("Tradesmen") 
      .eq("_id", userId) 
      .find(); 
  } ) 
  .then( (results) => { 
    // if an item for the user is not found 
    if (results.items.length === 0) { 
      // create an item 
      const toInsert = { 
        "_id": userId, 
        "email": userEmail 
      }; 
      // add the item to the collection 
      wixData.insert("Tradesmen", toInsert) 
        .catch( (err) => { 
          console.log(err); 
        } ); 
    } 
    // update buttons accordingly 
    $w("#button4").label = "Logout"; 
    $w("#button5").show(); 
  } ) 
  .catch( (err) => { 
    console.log(err); 
  } ); 

}
}

export function button5_onclick() {
wixLocation.to(/Tradesmen/Update/{ID}${wixUsers.currentUser.id});
}

Hi Victoria,

The first question is not related to wixCode. Please go to Help Center | Wix.com for getting the help you need.

Regarding the second question, do you use the input in order to submit a form?
If so, you can set it as ‘required’ in the input box settings and then the component will be invalid and will not let the form to be sent while adding a red indication).

If this is not the case, please explain in details and add only the relevant code.

Thank you,

Thanks for the quick reply. I will send support the first part.

WRT to the second bit. No, the user selects whichever trade the are looking for (i.e. electrician) from the first dropdown box and then in the ‘input’ box types the zip (Post) code they wish that trader to be located in (i.e. locally to them). Once the ‘Go’ button is pressed - the code should query the database and display the results in the table below (the table being hidden initially).

My code is :


import wixData from ‘wix-data’;

//For full API documentation, including code examples visit http://wix.to/94BuAAs

$w.onReady(function () {
//TODO: import wixData from ‘wix-data’;
});

export function searchButton_onClick() {
wixData.query(‘Tradesmen’)
.contains(‘title’, $w(‘#iAllTraders’).value)
.contains(‘postCode’, $w(‘#iPostCode’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
if($w(“#table1”).collapsed) {
$w(“#table1”).expand();
}
else {
$w(“#table1”).collapse();
}

}); 

}

Hi Victoria,

Here is a piece of code I wrote in order to help you:

$w.onReady(function () {
	$w('#iPostCode').required = true
});

export function searchButton_click(event, $w) {
	if (!$w('#iPostCode').valid) {
		$w('#iPostCode').updateValidityIndication()
	} else {
		// wixData.query...
	}
}

I’ll explain.

In the onReady function I set the text input as required. This code is not needed if you set the component as required in the settings panel:


In the searchButton_click event, I’m checking if the text input value is invalid. If it is, I’m updating the validity indication (which makes the input border red) and do not query the collection.
If it is valid => hooray!!

Good luck,

Thank you so much for this. I will give it a try :blush:

1 Like

P.s. I forgot to tell you that wix support fixed my initial problem. :grin:

1 Like

Good!
I hope I helped you fix the second one :slight_smile:

Hi Mor Gilad,

So, i added in your code and unchecked the box in the general settings.

My code now looks like this:

import wixData from ‘wix-data’;

//For full API documentation, including code examples visit Velo API Reference - Wix.com

$w.onReady(function () {
//TODO: import wixData from ‘wix-data’;
});

 **$w.onReady(function () {** 

$w(‘#iPostCode’).required = true;

});

export function searchButton_click( $w) {
if (!$w(‘#iPostCode’).valid) {

$w(‘#iPostCode’).updateValidityIndication();

} else {
// wixData.query…
}
}

export function searchButton_onClick() {
wixData.query(‘Tradesmen’)
.contains(‘title’, $w(‘#iAllTraders’).value)
.contains(‘postCode’, $w(‘#iPostCode’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
if($w(“#table1”).collapsed) {
$w(“#table1”).expand();
}
else {
$w(“#table1”).collapse();
}

}); 

}


However, it did insist that i add a semicolon at the end of each of the indicated lines …

But, So far so good …


BUT …
You can just select a trade/vendor and NOT enter anything in the Post code - press GO and this is the result.

I know i am missing something - i think my brain is fried i have looked at this for so long!!

I can’t really understand what is the problem.
Can you please send me your site url? I’ll try to have a look.

Sure, thank you

https://victoriashelley200.wixsite.com/askus

Hi Victoria,

I didn’t see my code when I entered your site.
Moreover, I meant you should check the checkbox (not uncheck it).
Moreover, my code needs to be added in the correct places.
Make sure you do it.

1 Like

Oh, let me go an check the box again - sorry i misunderstood you. Did i have the code in the right place from the excerpt i sent you?

Ok - i have rechecked the box. Is the code in the right place? It is still adamant that I add the 2 x ; where is indicated above …

Hi Victoria,

As we are really happy you give you a steer at the right direction, I’m afraid that we cannot write your code for you, and cannot debug this much of a code (really cannot, it’s very hard).
I suggest reading a bit about our APIs and articles.
If you still need some help in coding, you can always consider hiring a pro using Wix Arena .

Liran.

Thanks, I am a wix pro and a member of the arena.
I just need a little help is all. My code works but it doesn’t recognise what’s in the post code box so it doesn’t matter if it has something valid in it or it’s blank. I just wanted to make it a mandatory field with a valid entry.
I’ll keep trying :blush: