Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Select contents on start edit of input field
Select contents on start edit of input field [message #1858126] Thu, 16 March 2023 14:06 Go to next message
Nils Israel is currently offline Nils IsraelFriend
Messages: 72
Registered: May 2010
Member
Hi,
is it possible to automatically select the contents of an input field (String, Long, BigDecimal, ...) in Scout Classic when the users clicks in the field. The intention is to replace the contents by starting to type or to add, after using for example cursor keys or clicking another time like it is done e.g. in the address bar of chrome and edge?

I know that there is the setting:
  @Override
  protected String getConfiguredClearable() {
    return CLEARABLE_ALWAYS;
  }

and that would be the alternative if there is no such setting and it can't be added easily.
Thanks
Nils
Re: Select contents on start edit of input field [message #1858219 is a reply to message #1858126] Thu, 23 March 2023 10:31 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 256
Registered: March 2010
Senior Member
Hi Nils,

there is no such functionality. You could add it by extending the StringField.ts (and NumberField.ts), override _render() and add a listener, e.g.:
import {StringField} from '@eclipse-scout/core';

export class CustomStringField extends StringField {

  protected override _render() {
    super._render();

    this.$field.on('click', event => this.$field[0].select());
  }
}

This will always select all text, so the user won't be able to select only a part of the text, which is probably not ideal. You could use a mouseup listener instead of a click listener and do it only if the selection has not been changed or something like that.

See Extension by Sub-Classing for details about how to extend the StringField. If you only want specific StringFields to behave like that, you could use a @ModelVariant and add it to your Java StringField (e.g. @ModelVariant("yournamespace.Custom"). Or you could add a custom property and only register the listener when the property is true. That would require to extend StringField.java, JsonStringField.java and StringFieldAdapter.ts as well.
Re: Select contents on start edit of input field [message #1858289 is a reply to message #1858219] Mon, 27 March 2023 13:57 Go to previous message
Nils Israel is currently offline Nils IsraelFriend
Messages: 72
Registered: May 2010
Member
Hi Claudio,
for now I want to use it on all fields, so I will use the simple way and just replace the StringField. You are right, at least on larger fields the user should have the possiblilty to select text and adding the listener to 'mouseup' is working great.

import {StringField} from '@eclipse-scout/core';
export class MyStringField extends StringField {

  protected override _render() {
    super._render();

    this.$field.on('mouseup', event => {
      if (event.target.selectionEnd - event.target.selectionStart == 0) {
        event.target.select();
      }
    });
  }
}


Thank you.
Nils
Previous Topic:Gitlab CI/CD integration
Next Topic:Assertion error: No userId available
Goto Forum:
  


Current Time: Sat Apr 20 10:22:44 GMT 2024

Powered by FUDForum. Page generated in 0.03256 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top