Skip to content

Commit

Permalink
fix #83 #71
Browse files Browse the repository at this point in the history
  • Loading branch information
kou-yeung committed Mar 27, 2022
1 parent 5aa3b1a commit cff3e70
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Assets/WebGLSupport/WebGLInput/Wrapper/WrappedTMPInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using TMPro;
using WebGLSupport.Detail;
using UnityEngine.UI;
using System;

namespace WebGLSupport
{
Expand All @@ -24,8 +25,33 @@ class WrappedTMPInputField : IInputField
public string text
{
get { return input.text; }
set { input.text = value; }
set { input.text = FixContentTypeByInputField(value); }
}

/// <summary>
/// workaround!!
/// when use TMP_InputField.text = "xxx"; is will set the text directly.
/// so, use InputField for match the ContentType!
/// </summary>
/// <param name="inText"></param>
/// <returns></returns>
private string FixContentTypeByInputField(string inText)
{
var go = new GameObject("FixContentTypeByInputField for WebGLInput");
go.SetActive(false);
var i = go.AddComponent<InputField>();
i.contentType = (InputField.ContentType)Enum.Parse(typeof(InputField.ContentType), input.contentType.ToString());
i.lineType = (InputField.LineType)Enum.Parse(typeof(InputField.LineType), input.lineType.ToString());
i.inputType = (InputField.InputType)Enum.Parse(typeof(InputField.InputType), input.inputType.ToString());
i.keyboardType = input.keyboardType;
i.characterValidation = (InputField.CharacterValidation)Enum.Parse(typeof(InputField.CharacterValidation), input.characterValidation.ToString());
i.characterLimit = input.characterLimit;
i.text = inText;
var res = i.text;
GameObject.Destroy(go);
return res;
}

public string placeholder
{
get
Expand Down

0 comments on commit cff3e70

Please sign in to comment.