Best approach getting answer from multiplay text boxes - swift

I've created multiple text fields where each text field accepts only 1 character and then moves to the next box. I would like to check users answer when all the text fields are filled but I'm a bit confused as to how to do so.
My first approach was to create an answer String and every time textFieldDidChange is called I add to the String the textfield.text but how can I know when all the boxes been filled and call the checkAnswer function another issue is that if the user decides to fill the boxes in a different order then when I compare the user answer to the correct answer it obviously comes incorrect as the order is different.
[here's a pic of the boxes every game round it generates a different number of boxes depending on the answer

If you know how many number of textFields you have then, you can add a property observer to yourAnswerString and as soon as the value of yourAnswerString becomes equal to numberOfTextFields, it will call the check Answer function automatically.
var yourAnswerString = "" {
didSet {
if yourAnswerString.count == numberOfTextFields {
self.checkAnswer()
}
}
}

Related

need some javascript for a pdf form

not sure if I've come to the right place or not. Any help is appreciated.
I am creating a form that will post certain air quality test results on a building. Users will insert particular numbers in the form (e.g., concentration of certain gases, etc.). If number meets acceptable standards (e.g., below acceptable maximum), then I would like a check box to turn on that says the building meets the safety standards.
let A be air quality value
let B be maximum accepted value
let C be checkbox indicating pass
So, if A is less than B, then C is ON (pass) but if A is greater than B, C is OFF (fail)
Ideally, C will be a graphic of a green check mark or a red ex.
thx
You'll need to set up a file with your field and 4 "buttons" set to read-only which are really just holders for your graphics. One is the visible button that has its image replaced by the code, three of them are hidden, the check, the X, and a clear one for when the form is reset. Then add the following code to the Custom Format script of the field. The code will use the value of the field to swap the button icons. The value of 50 is arbitrary. Set it to the number you need.
if (event.value != "") {
if (event.value <= 50) {
this.getField("graphic").buttonSetIcon(this.getField("passed").buttonGetIcon());
}
else {
this.getField("graphic").buttonSetIcon(this.getField("failed").buttonGetIcon());
}
}
else {
this.getField("graphic").buttonSetIcon(this.getField("clear").buttonGetIcon());
}
You can download a working example from here.

Do I have to create a reference for each text I have in a panel, if I want to access them to modify?

I have a panel with 8 text field, 4 are used as descriptive field (what a label would do, basically), while the other 4 are modified with values.
I am creating a GameObject variable for every element that I have in the panel, using find to find the specific text element. I can leverage on the fact that each text object has only one text object attached to it, so I can address to it directly with GetComponent
panel_info = GameObject.Find("infopanel");
textfield1 = GameObject.Find("text_name");
textfield2 = GameObject.Find("text_age");
textfield3 = GameObject.Find("text_role");
textfield4 = GameObject.Find("text_field");
textfield1.GetComponent<Text>().text = "joe";
textfield2.GetComponent<Text>().text = "22";
textfield3.GetComponent<Text>().text = "striker";
textfield4.GetComponent<Text>().text = "attack";
While this works, I can't foresee myself creating 20-30 objects if a panel has more info to display.
Since I have the reference to the object Panel, is there a way to address directly the text field which is a child of the panel, using the text field name for example?
So if a panel has 4 text field, I can modify each of it addressing directly by name, and then using GetComponent<Text>().textto change the value.
You MUST NOT call GetComponent<Text>() each time you want to access/modify text.
This is an extremely basic fact about Unity.
It is immediately mentioned in the relevant manual entries.
Since you have 8 textbox and I don't know how long you update each one. It would be good if you cache all of them in the beginning of the game then use them later on without GetComponent<Text>(). This will improve performance a lot and make your frame-rate happy.
Array looks good for something like this. And you need to comment each one too.
public Text[] textBoxArray;
On the editor, Expand the "Text Box Array" and change the array Size to 8.
Now drag each GameObject with the text to the arrays in order. If you do it in order, you can easily remember their names and be able to access them in order.
For example, if the first text gameobecjt you dragged to the array is called text_name, the access it, you use textBoxArray[0]. The second text which is text_age can be accessed with textBoxArray[1]. .....
To make it easier for you later on, you should have multiple line comment that describes which array points to what.You do this so that when you return to modify your code months after, you won't have to look around in the Editor to find what points to what. For example:
/*
textBoxArray[0] = text_name
textBoxArray[1] = text_age
textBoxArray[2] = text_role
textBoxArray[3] = text_field
*/
No performance lost and that decreases the amount of code in your game.
Initializing the arrays by code instead of the Editor
Assuming you want to initialize the arrays by code instead of the Editor. You can do it in the start function like below.
public Text[] textBoxArray;
void Start()
{
//Create arrays of 8
textBoxArray = new Text[8]; //8 texts
//Cache all the Text GameObjects
textBoxArray[0] = GameObject.Find("/infopanel/text_name").GetComponent<Text>();
textBoxArray[1] = GameObject.Find("/infopanel/text_age").GetComponent<Text>();
textBoxArray[2] = GameObject.Find("/infopanel/text_role").GetComponent<Text>();
textBoxArray[3] = GameObject.Find("/infopanel/text_field").GetComponent<Text>();
}
You should notice that GameObject.Find() starts with "/" and that increases performance too as it will only search for Texts under "infopanel" instead of searching in the whole scene.
Assuming that your hierarchy is setup that all your TextMeshes are children of the panel, you could use the Transform.Find method to get each child, then it's TextMesh, and assign a value.
So, for example, if you wanted to assign the value "Joe" to the TextMesh attached to "text_name", which in turn is a child of "infopanel", you could do the following
panel_info = GameObject.Find("infopanel");
panel_info.transform.Find("text_name").GetComponent<TextMesh>().text = "Joe";

Updating the selected dropbox item in a GUI

Currently I have a GUI in which once a 'Submit' button is pressed the drop menu which is left blank is then populated by a calculated value determined by the three other values.
I have successfully figured out how to grab all of the values using this logic:
temp=get(handles.FSTOPpopmenu,{'String','Value'});
fstop=temp{1}{temp{2}};
if (strcmp(fstop,'Select'))
fstop = 0;
else
fstop = str2num(fstop);
end
I just have two questions about this that I can not seem to find an answer for.
How would I go about updating the 'empty' drop menu to the calculated variable (the calculated variable will already be one of the possible values in the predetermined list)?
How would I go about presenting an error, say if I have an if statement checking that the amount of zeros in the array? Would a pop up box be sufficient?
Cheers.
As for your first question matlab's set command is what you're looking for. The documentation is here. You would probably need:
MyValueIndex = find(DropDownValues==NewValue);
switch handleToChange
case handles.handle1
set(handles.handle1,'Value',MyValueIndex);
case handles.handle2
set(handles.handle2,'Value',MyValueIndex);
otherwise
error('Uh oh!');
end
Note that MyValueIndex is the index of dropdown box values that you want. Which is found with a find command on the actual value.
Question two is more of an opinion question but I think that a pop-up box describing the problem is sufficient. Maybe add in a system beep for good measure!
Reference:
http://www.mathworks.com/matlabcentral/answers/22734-resetting-a-pop-up-menu-in-a-gui
http://www.mathworks.com/help/matlab/ref/find.html
http://www.mathworks.com/help/matlab/ref/switch.html
For a popupmenu uicontrol the Value property determines which element of the String property is currently being displayed. Get the String; compare its contents to the calculated variable to get the index; then set that index as the Value property. If the calculated variable is not currently in the String then add it to the String and then set the Value. (Note when comparing you need to compare numbers to numbers or string to strings, so you may need to do an appropriate data type conversion first).
Use an errordlg.

GXT 3 spinnerField validation

I want to validate that user cannot change spinner value manually by typing in text box of spinner.
For example a field sales multiple = x which I fetched from server not fix.
and displays a spinner field with limitation of like bellow
spinner.setMinValue = x
spinner.setIncrement = x
spinner.setValue = x
so user forcefully select a value which is multiple with x. e.g. if x=3 the user have to enter 3,6,9... and so on.
So here my issue is if I type a 2 in spinner field text box. GXT widget accept that value.
Posible solutions:
Is there any predefined properties of spinnerfield that i forget to set it?
Is there any predefined validator for this?
Can I set text box of spinner field read only by css so user cannot focus on text box but still change a value.
If none of above how to achieve manually?
i've searched a bit in the different classes and I don't see either a precise method which would set what you want.
Don't know about one, and even with one, a validator doesn't change the value in the input field, but maybe it's enough for your needs.
You can disable the text input by calling setEditable(boolean) on the spinnerfield (testSpinner.setEditable(false);)
Maybe you could search around the IntegerPropertyEditor, I haven't tried but as long as a new Spinner is like this:
SpinnerField<Integer> testSpinner = new SpinnerField<Integer>(new NumberPropertyEditor.IntegerPropertyEditor());
you can seen that there is another Constructor for IntegerPropertyEditor, which takes a "NumberFormat" param, but there is no NumberFormart() constructor, so I'm not sure about how you create your own one, but that could be an idea (to format numbers in the input to be a multiple of the increment).
The last option would be that Sencha forgot this possibility and that you should report this as a "bug" on the forum ?
Hope to have helped a bit, good luck :).

How do I change a header cell when the page changes?

I have a PdfPTable in my document being written using iTextSharp. There are some header rows which get repeated whenever the table overflows to another page. One of those rows contains a cell with some text, e.g. "John Doe".
What I want is for that text to change to "John Doe (continued)" on each subsequent page. From what I can tell, I need to do something in the OnEndPage event that somehow manipulates the instance of the header cell for that page, but I'm struggling to find out how exactly to find the cell in the written content and then manipulate it.
How do I achieve this goal?
After some trial and error, I was able to get a working solution. I implemented the IPdfCellEvent which declares a single method, CellLayout. As per the iText documentation, this is called after the cell has been rendered, which means, the first time it is called it has rendered the cell for the very first page of the table. So, I use this call to add the extra text so that all subsequent renderings will include the additional text.
This is my interface implementation:
private class ContinuedCellEvent : IPdfPCellEvent
{
public void CellLayout( PdfPCell cell, Rectangle position, PdfContentByte[] canvases )
{
if ( !_continuationApplied )
{
// This is called AFTER cell rendering so this should set the cell for the next time it is rendered
// which will always be on a continuation.
cell.Phrase.Add( new Chunk( " Continued" ) );
_continuationApplied = true;
}
}
private bool _continuationApplied;
}
It is used when defining the cell:
cell.CellEvent = new ContinuedCellEvent();
Using onEndPage() could work, but I would implement the PdfPTableEventSplit interface if I were you. I'd use a membervariable cellContent and set it to "John Doe" upon creating the event instance. I would draw the content of cellContent in the tableLayout() method and change its content to "John Doe (continued)" in the splitTable() method.
Try it out and share your code. If it works, others will be helped; if it doesn't, I'll take a look to see what goes wrong (but please understand that I'm not a C# developer; I wrote iText in Java; I had to hire people to port it to C#).