- Home /
Clear fields after submit
I have a panel that has various input fields. When the user submits the information, it is saved in an SQLite database. I'd like to clear the fields once the info is submitted, but simply setting the string to "" doesn't work.
FieldText.text=""; What's the best way to clear them out? Thanks!
Perhaps my question is too vague: Here is the function
public void GetOilChangeData()
{
OilServiceDateField=OilServiceText.text;
OilLocationField=OilLocationText.text;
OilMileageField=OilMileageText.text;
OilLaborField=OilLaborText.text;
OilBrandField =OilBrandText.text;
OilPriceField= OilPriceText.text;
FilterBrandField= FilterBrandText.text;
FilterPriceField=FilterPriceText.text;
OilFilterPurchaseLocationField =OilFilterPurchaseLocationText.text;
DatabaseManager.Instance.SQLiteInit();
DatabaseManager.Instance.SaveOilChangeInfo(OilServiceDateField, OilLocationField, OilMileageField, OilLaborField, OilBrandField, OilPriceField,
FilterBrandField, FilterPriceField, OilFilterPurchaseLocationField);
}
Answer by jmgek · Dec 23, 2016 at 01:49 AM
when are you calling FieldText.text="";? Because there is no function to clear text field.
public InputField inputfieldname;
inputfieldname.Select();
inputfieldname.text = "";
Don't use answers as comments.
On the button you can add an event.
public InputField inputToClear;
Public void ClearFields()
{
inputToClear.text = "";
}
Something like that. Then call ClearFields when the button is clicked.
Sorry, are you telling me not to use answers as comments?
Oh wow, my bad. I thought you were the original poster for some reason. Sorry about that.
Look up at the original post, I added my function so you can see how I did it. Perhaps that will make things less vague?
In that case if you know you're always going to have 9 fields for your text just make an array and assign those oil data to it so you don't have to continue to assign them to your Oil* = Oil*.text.
but if you want to keep it more dynamic append them to a list and toss them in a foreach:
public void GetOilChangeData()
{
List<TextFeild> oilData = new List<TextFeild>();
oilData.Add(OilServiceText.text);
oilData.Add(OilLocationText.text);
//The rest of the variables
Database$$anonymous$$anager.Instance.SQLiteInit();
foreach(TextField text in oilData)
{
Database$$anonymous$$anager.Instance.SaveOilChangeInfo(text);
text.text = "";
}
//Or you could just pass SaveOilChangeInfo the list or array and handle it in that function.
I'm not 100% sure the class is TextField, so you may need to re do that part.
Answer by NNLV · Dec 23, 2016 at 08:20 AM
Try this, i'm using it :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InputHelper : MonoBehaviour {
public InputField clearIt;
public void submittingClear()
{
clearIt.text = "";
}
}
Remember to add the asset to the script :)!
And done! It should work!
Answer by Gilead7 · Dec 28, 2016 at 01:15 AM
jmgek, you had it right! Thanks for the help!
Glad to help, if you get the chance mark as "answered" so others know it's answered.
Your answer
Follow this Question
Related Questions
How to convert text field to input field and back again? 0 Answers
I have a C# script with InputField and I want to get text from this input field to another script 0 Answers
[SOLVED] InputField inputted text will not show up when it is called to show up in a text object? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers