Getting the text of an Input Field?Solved
Hello,

I was working on a admin panel for my team to use in the events, and was trying to make whitelisting easy with input fields but I can't seem to retrieve the text from the input box, am I just doing somthing wrong?

Thanks,
Travis Butts
It executes the command specified with text input as argument for the command.
In response to misticos ():
It executes the command specified with text input as argument for the command.
Could you give a example of the argument used?
It just sends a command u specified. So handle it like any other command and don't forget to specify the command itself :p afaik input field is used in Players Administration
In response to misticos ():
It just sends a command u specified. So handle it like any other command and don't forget to specify...
Right, but when does that command get called? When you type? When you hit enter?
When you unfocus (click on an another button or input field or something AFAIK, take a look at client code) or when u hit enter.
In response to misticos ():
When you unfocus (click on an another button or input field or something AFAIK, take a look at clien...
I am having the same issue, I don’t know what to pass through command to be able to retrieve the text as a argument

Sooooo, you'll have to make a couple of changes.
First is to define the inputfield itself:

/// <summary>
/// Input field object
/// </summary>
private class CuiInputField
{
    public CuiInputFieldComponent InputField { get; } = new CuiInputFieldComponent();
    public CuiRectTransformComponent RectTransform { get; } = new CuiRectTransformComponent();
    public float FadeOut { get; set; }
}

Once you have this, you'll need to extend the `CuiElementContainer` class to make it support the input field:

/// <summary>
/// Custom version of the CuiElementContainer to add InputFields
/// </summary>
private class CustomCuiElementContainer : CuiElementContainer
{
    public string Add(CuiInputField aInputField, string aParent = Cui.ParentHud, string aName = "")
    {
        if (string.IsNullOrEmpty(aName))
            aName = CuiHelper.GetGuid();

        if (aInputField == null) {
            return string.Empty;
        }

        Add(new CuiElement {
            Name = aName,
            Parent = aParent,
            FadeOut = aInputField.FadeOut,
            Components = {
                aInputField.InputField,
                aInputField.RectTransform
            }
        });
        return aName;
    }
}

Then you can add them to the UI (I tend to put them ontop of a panel to give it some shade behind it.
The command it expects is a generic `Command` for `CovalencePlugin` and a `ConsoleCommand` for a rust-specific plugin (Rust-specific should be avoided).

Command example:

private Dictionary<string, string> FExampleInputText= new Dictionary<string, string>(); // Format: <userId, text>

[Command("example.exampleinputtextcb")]
private void ExampleExampleInputTextCallback(IPlayer aPlayer, string aCommand, string[] aArgs)
{
    if (aArgs.Count() <= 0) {
        if (FExampleInputText.ContainsKey(aPlayer.Id))
            FExampleInputText.Remove(aPlayer.Id);

        return;
    }

    if (FExampleInputText.ContainsKey(aPlayer.Id)) {
        FExampleInputText[aPlayer.Id] = aArgs[0];
    } else {
        FExampleInputText.Add(aPlayer.Id, aArgs[0]);
    }
}
In response to ThibmoRozier ():
Sooooo, you'll have to make a couple of changes.
First is to define the inputfield itself:///...
Thanks so much! Just was playing around with it and got it to work, also just wanted to say you dont actully have to add those two classes at least for RustPlugin. Example of how I got mine working down below, thanks for the jumpstart!

First, just put this under your container or where ever you want to add it to.
var TestNameInput = new CuiElement
{
    Name = "TestNameInput ",
    Parent = ParentClass,
    Components =
    {
        new CuiInputFieldComponent
        {
            Text = string.Empty,
            CharsLimit = 40,
            Color = "1 1 1 1",
            IsPassword = false,
            Command = "example.exampleinputtextcb",
            Font = "robotocondensed-regular.ttf",
            FontSize = 10,
            Align = TextAnchor.MiddleLeft
        },

        new CuiRectTransformComponent
        {
            AnchorMin = anchormin,
            AnchorMax = anchormax
        }
    }
};

container.Add(TestNameInput);​


Then, make sure you add the dictonary at the top.

private Dictionary<string, string> FExampleInputText= new Dictionary<string, string>();​


Lastly, for RustPlugin classes you would use the ConsoleCommand which is shown down below.

[ConsoleCommand("example.exampleinputtextcb")]
private void ExampleExampleInputTextCallback(ConsoleSystem.Arg arg)
{
    BasePlayer player = arg.Player();

    if (arg.Args.Length <= 0)
    {
        if (FExampleInputText.ContainsKey(player.UserIDString))
            FExampleInputText.Remove(player.UserIDString);

        return;
    }

    if (FExampleInputText.ContainsKey(player.UserIDString))
    {
        FExampleInputText[player.UserIDString] = arg.Args[0];
    }
    else
    {
        FExampleInputText.Add(player.UserIDString, arg.Args[0]);
    }
}


Thanks for all the help, hope I can help out those that don't want to switch!

Again, avoid the legacy RustPlugin parent.. ;)

Won't be there in uMod

In response to ThibmoRozier ():
Again, avoid the legacy RustPlugin parent.. ;)Won't be there in uMod
It will be deprecated, but would encourage CovalencePlugin use. The type will be UniversalPlugin in uMod.
In response to Wulf ():
It will be deprecated, but would encourage CovalencePlugin use. The type will be UniversalPlugin in...
-Insert like here-
That. :)
In response to Wulf ():
It will be deprecated, but would encourage CovalencePlugin use. The type will be UniversalPlugin in...
The only really difference is the transfer from BasePlayer to IPlayer, right? I changed classes and that was really only noticable thing other then a few class differences. 
In response to BillyJoe ():
The only really difference is the transfer from BasePlayer to IPlayer, right? I changed classes and...
No, those can be used in any type of plugin. The only thing that different plugin types provide is various helpers and attributes; there are differences.
Locked automatically