- Home /
Question by
$$anonymous$$ · Aug 16, 2018 at 04:22 AM ·
scripting beginnerinputfield
set default value for inputfield with script
so theres an inputfield, you put in number hit calculate button, number goes through some equation and shows answer. when I dont put in any number and hit calculate, it shows error,
but I want something like, when you dont enter any value, it assumes the value to be zero, like so
if (InputField.text == null)
{
text = 0;
}
what I dont want is enter zero in Text here because it will overright place holder, which says enter value here, so placeholder is necessary. please help. thank you.
Comment
Best Answer
Answer by Hellium · Aug 16, 2018 at 06:36 AM
public void OnInputFieldValidated()
{
if( !string.isNullOrEmpty( inputField.text ) )
{
inputField.text = parseExpression( inputField.text ).ToString() ; // Supposing you have such function to parse an compute the result of the input field
}
else
{
inputField.text = 0.ToString();
}
}
Your answer
