Skip to main content

Is there a way to have a textbox select the contents on click?

 

We are using a SmartForm to edit existing data.  When the user clicks on the textbox to change the data, then the cursor is at the end of the existing data.  So they have to either backspace or double click so they can enter a new value.  Is there a way to have the existing data selected so when the user starts typing it replaces the existing data (like Excel or the this.select() in a web page?

 

Example - we have a value of 123 in the textbox.  The textbox places the cursor after the 3.  If the user wants to replace the 123 they have to either backspace or double click.

 

Hi Terry,

 

This is probably one of those times that will require some custom jquery put into the page to accomplish this task. While many will suggest that you can just put a literal control on the page and inject your script that way, I really don't like that approach. It fragments your custom code across your solution.

 

The literal approach would be a great way to test out the code, but for wider use and production purposes I would suggest then wrapping that code in a custom control that you can then drop on any form in your application and enable that functionality as it will inject the code into the page.

 

The benefit of this approach is that will give you a single code base to maintain so if you need to tweak it later you just update the control and the change is propagated to any form that uses the control. Much cleaner from a management perspective and should be relatively low level of effort as your control isn't going to do much.

 

There is a third option, but it would be technically unsupported by K2 and would be stepped on during upgrades but being just a small piece of script would be low risk which would be adding the code to the base form.aspx page. if you explore that route, take all the typical precautions when modifying delivered artifacts.

 

I would also strongly suggest that you open a feature request with K2 so that they can get this functionality on their radar and maybe into the product. I also recommend that anyone reading this post that is also interested in this functionality also open a feature request. Each request opened equals more demand for a feature which results in the feature becoming a hirer priority.

 

Hope this helps.

 

S.

 

 


Hi,

 

Please add the following script as an expression on a data label :

 

<script>
$(document).ready(function() {
$("input:text").focus(function()
{
$(this).select();
});
});
</script>

Note: make sure you check the "Literal" property on the data label


....and there is the literal control suggestion I said was coming. LOL 🙂   Great for testing, but chose a different mechanism for use across your solution.


Thanks to both of you for your answers.  Both very detailed and told me exactly what I needed to know.


Reply