12 Posts
Manish
5 years ago
Topic

I have a List & Search Type form that has only one input field called Username. I have set it to Exact matching, so it only returns back results if an exact match is found.

But if the Username field is empty and I hit enter, it returns with all the results, whereas it should not get back anything as the field is empty.

I have tried most of the other options in Match+Stage and Conditional States options, but I still get back all results on empty search as well. I want it to not return anything if the Username input field is empty.

Get a Book for SEBLOD
1283 Posts
Bucklash
5 years ago
9
Level 1

If search field is empty then it is not used in search... need to have default value like “ “ etc...  can do that a fee different ways, depends on your preferred approach

12 Posts
Manish
5 years ago
0
Level 2

Hey, thanks for your reply. I just set the input field Default value in the Live+Live Value section to a single space, and saved it. But when I open the form it doesn't show the space in the input field, and when I hit enter I still get all the values.

(I'm sry is that what you meant that I should try?)

12 Posts
Manish
5 years ago
7
Level 2

Or any other approach that you suggest that I can try?

1283 Posts
Bucklash
5 years ago
6
Level 3

Ah thought that might work

another one is to have a text field (Username2) with same storage as the field you are searching (Username)

Have live value of "Username2" as "some value" ie current user.

Then using conditionals, enable this field if "Username" is empty.

12 Posts
Manish
5 years ago
0
Level 4

I did this- UserName2 is enabled if UserName isEmpty AND UserName2 is disabled if UserName isFilled

What happens is, the first time the page loads, UserName2 has some default val and that stops the empty UserName from getting submitted(and does not show any results, which is correct). But once I put a value for UserName and values are displayed, UserName2 becomes empty and then it never has a value again even if UserName is empty (and then again all rows are displayed).

Sry but I used quite a few different permutations of that and even those didnt work.

12 Posts
Manish
5 years ago
4
Level 4

Is there a way that I can call JS on onSubmit of the form, or clicking Enter on UserName field that can check if field isEmpty then that should not submit anything (like a break; or return False;) ?

1283 Posts
Bucklash
5 years ago
3
Level 5

probably. is js way but don’t know :)

Maybe apply live value to username2 instead of default value.

Sometimes I use rokpad to allow me to enter text without surrounding <p> getting added. I then assign values by using freetext field with defaultvalue as “1” etc

If I wanted people to only search exact terms from db i.e he users exact name then I would use select dynamic and maybe have search button disabled bu having it as disabled if field is empty (and having tick so that opposite enables it)  and have live value as some dummy value...

there is a beforesearch field but never used it

12 Posts
Manish
5 years ago
2
Level 6

I tried a lot of permutations and combinations with Seblod Field Validations but it won't do what I wanted it to do. 

But this is how I finally solved it- I created a new 'Field' in Seblod and set it's type to Script(JS), which basically creates a JS file for us that can be used with any form/list search. 

Now to connect this JS file with my form, I added this newly created 'Field' as a Hidden Field on my form. 

Then it was as simple as adding preventDefault() and return false; on form submission inside the JS.

1283 Posts
Bucklash
5 years ago
1
Level 7

cool

can you share the js?

12 Posts
Manish
5 years ago
0
Level 8

This is my JS- (main function is called first which inturn calls loadChecks function)

function main() { 

loadChecks(); //calling the function that checks the search inputs } 

function loadChecks() { //checks on first name field 

var fname = 'user_first_name'; 

var ids = '#'+fname; 

jQuery(ids) .on('blur', function(e){ e.preventDefault(); //stop form submission onBlur 

return false; }).keypress(function(f){ 

if(f.keyCode == 13 || f.keyCode == 9) //if enter or tab is pressed { 

if(jQuery(ids).val() == ''){ f.preventDefault(); //if first name field is empty, stop submission return false; } } }); 

}

Hope this makes sense.

Get a VIP membership