How to bind an EditableTextBox::OnChanged?

Hey there,

Can someone please help…

In the .h:
UPROPERTY(meta = (BindWidget))
class UEditableTextBox* ServerHostName;

In the .cpp:
if (!ensure(ServerHostName != nullptr)) return false;
ServerHostName->OnTextChanged.AddDynamic(this, &UMainMenu::ValidateServerNameText()); // ERROR

Please can you tell me how to correctly set this up?

I’d like the function ‘ValidateServerNameText()’ to fire each time the text is changed.

Where does this line have to go:
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEditableTextBoxChangedEvent, const FText&, Text);

I’d like my function to be able to count the characters of the input text and clamp them to a MaxCharacters variable.
Therefore does my function have to have these arguments:
ValidateServerNameText(const FText&, Text)?

Any help would be greatly appreciated.

Hey !
OnTextChanged is of type FOnEditableTextBoxChangedEvent ( as you noticed )
this mean it pass an arg to the binded method ( const FText& Text, as you pasted )

so you need UMainMenu::ValidateServerNameText to return void and take an arg, but you also need it to be a “UFUNCTION” to be able to bind it :

UFUNCTION()
 void ValidateServerNameText (const FText& Text);

if you set text from here ( to clamp it or anything ), it will make a recursive call of your event, it’s not really a problem, but if you have some heavy task, take care of that with a bool to prevent that

to bind, you need to pass a ref to the method :

ServerHostName->OnTextChanged.AddDynamic(this, &UMainMenu::ValidateServerNameText);

Ok, I get this bit, I missed out the UFUNCTION()

Though how do you bind my function to the event?

if (!ensure(ServerHostName != nullptr)) return false;
ServerHostName->OnTextChanged.AddDynamic(this, &UMainMenu::ValidateServerNameText());

Ok, I get this bit, I missed out the UFUNCTION()

Though how do you bind my function to the event?

if (!ensure(ServerHostName != nullptr)) return false;
ServerHostName->OnTextChanged.AddDynamic(this, &UMainMenu::ValidateServerNameText());

i’ve updated my answser, but you need to pass a ref to the method without the “()” :

ServerHostName->OnTextChanged.AddDynamic(this, &UMainMenu::ValidateServerNameText);