Skip to content

Instantly share code, notes, and snippets.

@bitinn
Created March 1, 2018 15:38
Show Gist options
  • Save bitinn/e22176b5aeec5ae12a78f388b4ee2b9e to your computer and use it in GitHub Desktop.
Save bitinn/e22176b5aeec5ae12a78f388b4ee2b9e to your computer and use it in GitHub Desktop.
Fake OnSubmit for Input Field
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace BeginHQ.Utility {
/*
redirect submit event to parent
*/
public class UISubmitInput : MonoBehaviour {
private void Awake () {
var input = gameObject.GetComponent<InputField>();
input.onEndEdit.AddListener((s) => {
HandleSubmit(input);
});
}
private void HandleSubmit (InputField input) {
var ev = new BaseEventData(EventSystem.current);
ExecuteEvents.ExecuteHierarchy(transform.parent.gameObject, ev, ExecuteEvents.submitHandler);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment