I’m attempting to adjust the input field component so that the field is selected on point Up instead of pointer down. At its current state the input field is selected when a user accidentally starts their drag gesture across it.
I’d like to swap this into OnPointerUp to avoid this.
public override void OnPointerDown(PointerEventData eventData)
{
if (!MayDrag(eventData))
return;
EventSystem.current.SetSelectedGameObject(gameObject, eventData);
bool hadFocusBefore = m_AllowInput;
base.OnPointerDown(eventData);
if (!InPlaceEditing())
{
if (m_Keyboard == null || !m_Keyboard.active)
{
OnSelect(eventData);
return;
}
}
// Only set caret position if we didn't just get focus now.
// Otherwise it will overwrite the select all on focus.
if (hadFocusBefore)
{
Vector2 pos = ScreenToLocal(eventData.position);
caretSelectPositionInternal = caretPositionInternal = GetCharacterIndexFromPosition(pos) + m_DrawStart;
}
UpdateLabel();
eventData.Use();
}
But I get these errors.
`UnityEngine.UI.InputField.MayDrag(UnityEngine.EventSystems.PointerEventData)’ is inaccessible due to its protection level
Hi, I know this was a while ago, but I am attempting to do the same thing. Did you end up getting it to work? If so, where did you put the code above? Is it just another script attached to the InputField gameobject, or were you able to modify the actual InputField script that Unity provides?
And then modify the InputField script as a new class. I just renamed it customInputField or something of the sort. And then I could do what ever I wanted to in my own set.
@Kellyrayj Cool thanks! Could you provide more detail on how to make the InputField be selected/in focus only on OnPointerUp? I tried simply changing the OnPointerDown method name to OnPointerUp, but it did not work as expected. It did prevent it from being clicked on initially, but it still does not enable scrolling to work when the finger starts over the field. It also doesn’t allow the field to be selected properly at all… Thanks again!