Simulate enter key press

Hello,

I have a parameter text box and I want to simulate enter key after every character written in the text box.

It is possible do this?

Thank you!

1 Like

Hi Costin

I don’t this is possible, but happy to be proven wrong.

My guess is that the official response will be something along the lines of presuming that you want to do this in order to filter as you type. They will then say that such an approach will run into issues as the filter keeps trying to update as you type, thus slowing down the typing and potentially frustrating the users.

If you held a gun to my head I’m sure I could come up with something, but it would definitely be an unrecommended method :wink:

Maybe just having a ‘submit’ button alongside the box would help guide your users how to use this filter type? The button doesn’t actually have to do anything, as just clicking outside the text box will update the value.

Hi Costin,

We purposely only hook into the ‘change’ event from the browser as we don’t want the parameter to be perceived as changed every time the user types a character. If we forced an update on every keystroke, you’re going to be spamming the server with data requests and causing really poor performance. If you really want to do something like this you can probably hook up the ‘key down’ event on the text box and handle it form there but we really don’t recommend this for performance reasons.

https://www.w3schools.com/jsref/event_onkeydown.asp

I personally agree with David’s point on adding an update button.

I agree with Davis and Jeff.
I am also wondering what the use case is to even have this done, it has to be a very edge special circumstance case.
It is possible that if we know the use case we might come up with a way to get to the goal that is not so extreme.

Thank you for your ideas!

I found a trick let’s say:
On the parameterTextbox I put a script on the click event. When is clicked, a timmer will start and will run this script:
// debugger;

// if(parameterTextBox2.control.value=="")

// {

// var viewParameter = this.parentView.control.getViewParameterByName("viewParameter9");

// // Reset the view parameter

// viewParameter.parameterValue.clearValues();

// viewParameter.parameterValue.clearTokens();

// // Create new token and set to "All"

// var myToken = new dundas.data.ParameterToken({

// "caption": "All",

// "id": dundas.constants.ALL_TOKEN_DEFINITION_ID

// });

// // Assign the newly created token

// viewParameter.parameterValue.token = myToken;

// // Reset modified time to take precedence

// viewParameter.invalidateParameterValueLastModifiedTime();

// // Load changes

// viewParameter.refreshAllAdapters();

// }

// else

// {

// var x=parameterTextBox2.control.value;

// parameterTextBox2.control.value=x;

// }
The timer will stop after a hover action on some elements.
You’re right about the overload of the server.
I am still thinking about a function regarding key press action in javascript.