I am using NGUI's UIInput class to accept text input from user. when i start typing in text box in mobile devices. a key board appears and it has an another textbox within it self, with "OK"/"Done" button (Like a keyboard accessory view, if we're talking about iPhone).
Can i disable that text box appearing within keyboard ? Or its not even possible and i am shooting just blanks ?
From what i could gather by search for a while is, the appearance of keyboard is handled buy Unity's "TouchScreenKeyboard" class. but according to Unity Scripting reference there is nothing which could hide the textfield inside the keyboard.
Unity Scripting reference: TouchInputKeyboard
PS:- I should still be able to put input in textbox by directly typing into them, i just want an extra textbox within the key board to be removed.
TO be more clear i have attached images explaining this
This is the screen.
When i start typing in one of the textbox. a keyboard appears like the following.
as you can see the text box just above the keyboard is not the original one.
Did you try checking "Hide Input Check box" in Inspector view of that UIInput Textbox ?
private void OnGUI()
{
TouchScreenKeyboard.hideInput=true;
}
I don't know why it is, but I have had this problem as well and the "hide input" checkbox for some reason doesn't seem to do really anything other then change the keyboard text box from one line to multi line.
I did a little bit of digging and came across a quick lead that will enable that hide input check box.
This fix is Update() in UIInput.cs around 650
else if (inputType == InputType.Password)
{
TouchScreenKeyboard.hideInput = true;
kt = TouchScreenKeyboardType.Default;
val = mValue;
mSelectionStart = mSelectionEnd;
}
else
{
if(hideInput)
{
TouchScreenKeyboard.hideInput = true;
}
else
{
TouchScreenKeyboard.hideInput = false;
}
kt = (TouchScreenKeyboardType)((int)keyboardType);
val = mValue;
mSelectionStart = mSelectionEnd;
}
I added a check in the else statement
Related
I am developing a simple app using Maui .net but facing some challenge perhaps you can give some advice.
I have a multiline text field of type "Editor" and I have one button. The onclicked event of the button should insert the button label text into the Editor mentioned above (very simple task). Now, the issue is when I use the myEditor.Text.Insert(myEditor.Text.Length, myButton.Text) the inserted text inserts fine, but the blinking text cursor moves to the far left of the Editor field, instead of staying at the far right.
I tried working around this issue but manually moving the text cursor using the myEditor.CursorPosition but the problem is what if the user decided to manually change text cursor location? then pressing the button would insert at the myEditor.Text.Length index, thus ignoring the user's intent to insert the text at a specified index.
I wasn't able to find a method that triggers an event when the text cursor moves inside a text Editor in Maui (so that I can handle it in my own way)
Note: When typing using the Android keyboard, there are no issues at all. but only if inserting text programmatically using .Insert(index,string)
Thanks.
You can try to use the handler to get the cursor position when you insert the text into the Editor.
Declare the control on the android platform:
#if ANDROID
AppCompatEditText nativeEditText;
#endif
Create the method which can get the control's cursor position for android:
void GetCursorPosition ()
{
Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
#if ANDROID
nativeEditText = handler.PlatformView;
});
}
Add code in the button's clicked event:
int cursorPosition = 0;
private void Button_Clicked(object sender, EventArgs e)
{
cursorPosition = nativeEditText.SelectionStart; //get the cursor position if user chooses a position by tapping the editor
string insertText = button.Text;
if (nativeEditText.IsFocused == true)
{
editor.Text = editor.Text.Insert(cursorPosition, insertText);
editor.CursorPosition = cursorPosition + insertText.Length;
//set the position at the end of text inserted
}
else
{
editor.Text = editor.Text.Insert(editor.Text.Length, insertText);
}
}
Updating Visual Studio to version 17.3.0 Preview 5.0 fixed the issue without further tweaks. This fix came in parallel with the time I was facing this issue and looking for a fix 😅
I am testing adding a comment to my app, on my other UI tests I have used the typeText function and everything works perfectly fine. I have also clicked to make Connect hardware keyboard' is off. The app terminates testing and shows the error UI Testing Failure - Neither element nor any descendant has keyboard focus during the addComment method. Any ideas?
func testAddComment() {
let featuredPage = self.app.tabBars["Featured"]
if featuredPage.exists {
featuredPage.tap()
}
sleep(2)
let featuredOffer = self.app.tables.cells.elementBoundByIndex(1)
if featuredOffer.exists {
featuredOffer.tap()
}
sleep(2)
let addComment = self.app.staticTexts["Add a comment"]
if addComment.exists {
addComment.tap()
addComment.typeText("Test comment")
}
sleep(2)
let postComment = self.app.buttons["Send"]
if postComment.exists {
postComment.tap()
}
sleep(2)
}
Likely cause:
An extremely common cause of this symptom is to have enabled a parent view of the field in question as an accessibility element. Ensure that none of the parents of the field are enabled as accessibility elements, and the problem is likely to be resolved.
Explanation
This error message can be particularly confusing when you can see that a previous step in the XCUITest has correctly activated a text field or similar as the first responder, the keyboard has appeared, and functionally the field has keyboard focus.
Essentially, the error message is slightly misleading as the tendency is to focus on the keyboard focus part and think that it is telling you that nothing has keyboard focus. Instead, what the message is telling you is that none of the accessibility elements that XCUITest can access have the keyboard focus. And so it can't direct text to the field in question.
Accessibility elements cannot have children that are also accessibility elements. Therefore, if you place a number of fields inside a view, but then mark that parent view as being an accessibility element, all of the field as its subviews become invisible to the accessibility frameworks. You can see and verify this is what is happening using the Accessibility Inspector app on the Mac alongside the simulator: the fields you are trying to target will not be selectable, and instead there will be a parent view that is.
I found the way around this best was to use menuItem and to paste what I wanted to the textField . This was a strange problem as both textField and staticText both didn't allow the test to run functionally. This is an issue I have reported to apple.
Here is my fix
let addComment = self.app.staticTexts["Add a comment"]
if addComment.exists {
addComment.tap()
UIPasteboard.generalPasteboard().string = "Test Comment"
let commentTextField = self.app.staticTexts["Add a comment"]
commentTextField.pressForDuration(1.1)
sleep(1)
app.menuItems.elementBoundByIndex(2).tap()
}
You can only use .typeText() on an input element. Static texts are not input elements - they're just text. Your addComment constant is probably the placeholder text within your text field. Tapping on the placeholder text probably activates the text field and keyboard, but you cannot call .typeText() on the placeholder text as the text field is its parent, not its descendant.
You need to call .typeText() on your text field, which should have focus after you tap in it.
let addComment = self.app.textFields["addCommentIdentifier"]
if addComment.exists {
addComment.tap()
addComment.typeText("Test comment")
}
You can try solving this issue by using .doubletap() before you & enter the value in .typeText(string) it worked for me.
let addComment = self.app.staticTexts["Add a comment"]
if addComment.exists {
addComment.doubleTap()
addComment.typeText("Test comment")
Turn off I/O -> Keyboard -> Connect Hardware Keyboard in the Simulator menu.
When this option is on, the Simulator doesn't bring up the soft keyboard, so the OS (sometimes) thinks the text field is not focused. Most of my tests have no problem typing in text fields with this option on, but some fail, especially search bars.
I'm using an Input Field in a Unity 3D game. When I enter text on my Windows 10 Mobile, and push the back button to dismiss the keyboard, Unity thinks I want to clear the Input Field. This behavior is not even mentioned in the documentation and I have not found a way to override it. I'd like to make it so the user can use the back button to dismiss the keyboard without reverting the Input Field. Any suggestions? Is this just a bug with Unity?
You can see the source code of InputField here: https://bitbucket.org/Unity-Technologies/ui/src/0155c39e05ca5d7dcc97d9974256ef83bc122586/UnityEngine.UI/UI/Core/InputField.cs?at=5.2&fileviewer=file-view-default
Apparently, clearing the field on escape is made by design. look at line 980 - 984:
case KeyCode.Escape:
{
m_WasCanceled = true;
return EditState.Finish;
}
What you can try is to create your own subclass of InputField and override the function
protected EditState KeyPressed(Event evt)
Of course it is not really clean, since you'll have to copy everything that the base InputField does in this function, except for lines 980 - 984.
The function KeyPressed cant be overridden.
I just added that in my function that listens on the value changes of the inputField:
if (Input.GetKeyDown (KeyCode.Escape)) {
return;
}
And it does exactly what is necessary :)
I'm using complete.ly for a site intended for use on a touchscreen. The keyboard only appears on-screen if the selected element is a textfield or input, the code for that is:
if( (this.input_target.is('input') || this.input_target.is('textarea')) && this.input_target.parent().find('.popover').length == 0)
Is there anyway you guys can think of that I can either change the keyboard logic to include the div that complete.ly is using, or maybe change complete.ly to make this work?
I guess a better way for me to ask this would be if there is any way to detect when complete.ly's text box has focus.
I am not sure I understand the original question but I do understand your last comment:
I guess a better way for me to ask this would be if there is any way to detect when complete.ly's text box has focus.
well, there is a way to see when completely's text box (input type) has focus.
if you look at the documentation it says:
// For no-big-deal hacking
c.wrapper
c.prompt
c.input
c.hint
c.dropDown
so you can access the input and do something like this:
if (c.input.addEventListener) {
_c.input.addEventListener("focus", yourHandlerFunction, false);
}
else {
_c.input.attachEvent("onfocus", yourHandlerFunction);
}
I've faced up with the following problem:
I have a scroll area which contains list of input text fields.
I use
ontouchmove = function(e){ e. preventDefault(); }
to prevent global scroll of the page. It works fine except cases when gesture begins from input field.
How can I prevent global scroll of the page when first touch traps to the input field?
Thanks.
I believe you want to capture the touchmove event using the addEventListener function so that the even doesn't "bubble". Try this:
/* This code prevents users from dragging the page */
var preventDefaultScroll = function(event) {
event.preventDefault();
window.scroll(0,0);
return false;
};
document.addEventListener('touchmove', preventDefaultScroll, false);
this might help
the section "MORE SPECIALIZED SOLUTION" might be what you are looking for.