Conditional Default Button

  

Hey guys,

I have a screen where I can have 2 table records which one has a filter.

This screen is conditional, so only one of the table records will load and his associated filter.

What I need to do is to define the default "Search" button so that when the user is writing something in the filter inputs he can press Enter and search without having to click the button.

I've seen that I can't make a conditional default in "Is Default" option like: if(boolean,true,false) so I looked out and found out some JS that works with this. 

So I made a condition expression that depending on the condition will add the class 'Is Default' to the button I want and I'm also adding a keydown click to the according input for example:


SyntaxEditor Code Snippet

"<script type='text/javascript'>
$(document).ready(function()
    {
        $('#" + BotaoProcurarWS.Id + "').addClass('Is_Default');
        $('#" + Input_Filter1.Id + "').keydown(function(e) 
        {
            if (e.keyCode == 13)
            {
                $('#" + BotaoProcurarWS.Id + "').click();
                return false; 
            }
        });
    }
);
</script>"


The thing I want to ask is: Do I have to do this-this way? Do I need to add the keydown press function to every input in my filters? 

Thanks in advance,

VC

Solution

Hi Vincent,

That's one way of doing it. And I would say that yes: You will have to do it to every input.

Two other ways:

  1. Your Default button has display none; It's bound to an action (with method Ajax Submit) that inside will do a widget click on the button you want.
  2. Your Default button has display none; On its extended properties add an onClick property that will do something like: "$('#"+Ok1.Id+"').click();" to click on button Ok1, where button Ok1 is the button you want to be the default in that case.

Cheers,

José

Solution

Just to ask...

Can't you just use a SINGLE search/filter bar for both tables, showing/hiding specific elements for each one depending on which one is visible?

This way you don't need to worry about multiple default buttons.

Another option is to put both tables/search&Filter in web blcoks (separated ones).
Now you can have the default buttons defined on both web blocks and chose wich web block to show based on your condition.

Cheers.

José Costa wrote:

Hi Vincent,

That's one way of doing it. And I would say that yes: You will have to do it to every input.

Two other ways:

  1. Your Default button has display none; It's bound to an action (with method Ajax Submit) that inside will do a widget click on the button you want.
  2. Your Default button has display none; On its extended properties add an onClick property that will do something like: "$('#"+Ok1.Id+"').click();" to click on button Ok1, where button Ok1 is the button you want to be the default in that case.

Cheers,

José

Hello Sr. José,

Obviously one of your solutions will fit better cause I won't have to add the Key Listener to every input that I have and that I may add in the future.

I will go through the first one which works perfectly.

I would like to thank you for helping me,

Cheers,

VC


Eduardo Jauch wrote:

Just to ask...

Can't you just use a SINGLE search/filter bar for both tables, showing/hiding specific elements for each one depending on which one is visible?

This way you don't need to worry about multiple default buttons.

Another option is to put both tables/search&Filter in web blcoks (separated ones).
Now you can have the default buttons defined on both web blocks and chose wich web block to show based on your condition.

Cheers.

Hey Eduardo,

indeed it should be a possible solution, but my filters are not equal in any way, logic associated with inputs, buttons, displays, CSS ... so that would require me a lot of work ( unnecessary I guess ) to accomplish it.

But, I enjoyed the second option you gave me,

Thanks for it m8,

VC


Vincent Colpa wrote:

Eduardo Jauch wrote:

Just to ask...

Can't you just use a SINGLE search/filter bar for both tables, showing/hiding specific elements for each one depending on which one is visible?

This way you don't need to worry about multiple default buttons.

Another option is to put both tables/search&Filter in web blcoks (separated ones).
Now you can have the default buttons defined on both web blocks and chose wich web block to show based on your condition.

Cheers.

Hey Eduardo,

indeed it should be a possible solution, but my filters are not equal in any way, logic associated with inputs, buttons, displays, CSS ... so that would require me a lot of work ( unnecessary I guess ) to accomplish it.

But, I enjoyed the second option you gave me,

Thanks for it m8,

VC


The second solution will require no extra work at all, just move the filter / table to its own web block and use an IF do show one or another in the page (at first, at least).

Cheers.