Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Gilead7 · Dec 22, 2016 at 07:58 PM · c#textinputfield

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);
 
     }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

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 = "";
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FirePlantGames · Dec 24, 2016 at 05:39 PM 1
Share

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.

avatar image jmgek FirePlantGames · Dec 24, 2016 at 05:46 PM 0
Share

Sorry, are you telling me not to use answers as comments?

avatar image FirePlantGames · Dec 24, 2016 at 05:52 PM 0
Share

Oh wow, my bad. I thought you were the original poster for some reason. Sorry about that.

avatar image Gilead7 · Dec 26, 2016 at 07:11 PM 0
Share

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?

avatar image jmgek Gilead7 · Dec 26, 2016 at 07:40 PM 0
Share

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.

avatar image
0

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 :)!

alt text

And done! It should work! alt text


skærmbillede-2016-12-23-kl-150610.png (36.6 kB)
skærmbillede-2016-12-23-kl-150850.png (23.2 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Gilead7 · Dec 28, 2016 at 01:15 AM

jmgek, you had it right! Thanks for the help!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jmgek · Dec 28, 2016 at 07:01 PM 0
Share

Glad to help, if you get the chance mark as "answered" so others know it's answered.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

267 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges