openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

adding onfocus event to sap.m.Input

Open Jitterer opened this issue 7 years ago • 9 comments

Hi, I don't know if here is the right place to start a discussion about new features. I'm missing on some classes like Input the onfocus event (especially for adding it in XML view). I know that I can set an event via controller. But in some cases you have a form with a lot of input boxes and it doesn't make sense and comfort to add these in the controller. Great would be this: <Input onfocus=".myEvent" />

Do you agree? BR

Jitterer avatar Nov 20 '19 09:11 Jitterer

What is exactly the use case?

stephania87 avatar Nov 20 '19 09:11 stephania87

@stephania87 usecase is, that I can define in XML view on focus events which executes my defined method in controller, that I can take any action I want. For example: when I click in the input field, it should automatically select all/partly content of this input field. So I could execute in controller e.g. something like oEvent.getSource().selectText(0, 999) or var oInput = this.byId(oEvent.getSource().getId()); oInput.selectText(0,999)

I dont want to set addEventDelegate in the controller for some/all input field.

Jitterer avatar Nov 20 '19 12:11 Jitterer

getValue method will give you the current string in the input field. liveChange event will give you any newly added character. The part with the selection of X characters in the input may interfere with the autocomplete and the existing highlight of text. Can I get the full use case in order to forward the question. What is the demand for this type of custom highlight and/or selection of text, or else?

stephania87 avatar Nov 21 '19 21:11 stephania87

I dont know how I can make it more understandable use case than in this sentence: "when I click (focus) in a sap.m.Input field, I want that the whole content should be selected" but that is only one possible use case.

I just want to achive this function like below but definable in xml view:

var oInput = this.byId("anyID")
.addEventDelegate({
    onAfterRendering: function(){
        oInput.focus();
    }
});

somthing like <Input focus="myFunction" />, where focus is the current not present focus event handler

or in pure HTML <input type="text" onfocus="myFunction(this)">

I think there are hundreds of use cases out :)

Jitterer avatar Nov 22 '19 16:11 Jitterer

@stephania87 The use case can be found here: https://stackoverflow.com/q/58934859/5846045

What I want is a formular and a possibility, that when I navigate e.g. with keyboard through a table with input fields, that every time when I press tab or arrow up/down to jump to next input field, the whole content of the box should be selected. (...) Example: https://ui5.sap.com/#/entity/sap.m.Table/sample/sap.m.sample.TableEditable (Click on Edit). When tabbing, it automatically selects the text. But it doesn't work with up/down arrow.

IMHO, controls shouldn't expose basic browser events to be handled within the view definition. Instead, the actual enhancement request here would be to allow selecting all input text when navigating with up/down arrow keys, too, in the case of sap.m.ListBase/.Table with the keyboardMode "Edit".

Either way, a simple notepad control would also do the job: https://embed.plnkr.co/98BIbMEIujbzBXqU

boghyon avatar Nov 25 '19 12:11 boghyon

IMHO, controls shouldn't expose basic browser events to be handled within the view definition

well, that would mean that every event like change, liveupdate, press and all the others shouldn't be available. IMHO all usefull events like the mentioned one including an onfocus event should be made available to the view or none of them. but some yes and some not is surely no strategy I think.

and please keep in mind that the use case mentioned above is just one example. it's not the first time I'm missing the focus event :)

Jitterer avatar Nov 25 '19 21:11 Jitterer

Please provide a list of the use cases where you need that event (a context - doing react, doing tests, etc.), beside highlighting the whole text/part of the text on accessing an Input control on navigation in a table/list. What the enduser should see on screen, do as a task which can be handled with onfocus. For example:

  • When the user types in an Input, each character must be validated = liveChange
  • When the user is done with the input, the value must be used in code, submitted to backend - change

You started with "there is a form with multiple fields" and that you force focus on an Input. What should follow? Everyone is welcome to add a use case.

Why I ask, because I have to forward to a dev team for evaluation the context :

  • if the context is valid for all controls, this is core level
  • if the context is valid for a certain container, I need to know which container/s
  • if the context is valid only for the input, this is on control level (all InputBase controls or certain ones depend on the context)

stephania87 avatar Nov 26 '19 19:11 stephania87

Since there is no response from the author for more than 4 weeks I'm closing the ticket.

Martotko avatar Dec 21 '20 13:12 Martotko

A use case for the onFocus event is the following. While the user is editing a paricularly "difficult" field, we show a helper text in the help box. The content of the help box corresponds to the field the user currently focused.

mhchem avatar Jan 22 '25 17:01 mhchem