change UITextField accessibility description - iphone

Is there a way to set the accessibility label of UITextField to be something other than the "text field". So instead of calling "text field", I want to name it "code verification field".

My advice would be to not try to outsmart the system on build-in Voice Over outputs.
"Text field is editing" is to a blind user the audible equivalent to "This item is selected and there is a blinking cursor in it".
Same as you are unlikely to remove/change the blinking cursor from your UITetxtField you shouldn't try to remove/change that built in output.
Feel free to use the accessibilityLabel and accessibilityHint to add more context to this field.

How to Quiet "Text Field" & Options to Replace It
I posted a related answer that illustrates a few ways to stop VoiceOver from announcing "text field" for a UITextField.
This is the a code excerpt from that answer.
Quieting "Text Field"
let textField = UITextField()
textField.accessibilityTraits = UIAccessibilityTraitStaticText
Replacement Text
You could use the accessibilityHint for the alternate control name you want "code verification field"
textField.accessibilityHint = "code verification field"
accessibilityLabel would also work. The practical difference is that accessibilityLabel is read first, then textField.text (the text entered in the UITextField), then the accessibilityHint.
The following is read as: "label, text, (short pause...) hint"
textField.accessibilityTraits = UIAccessibilityTraitStaticText
textField.accessibilityLabel = "label"
textField.text = "text"
textField.accessibilityHint = "hint"
You can find out more about UIAccessibility Element properties in Apple's API reference.

I believe you have to set the field's accessibilityLabel property (part of the UIAccessibility protocol). Perhaps you also have to play around with the accessibilityTraits property to override the UIKit labeling.

As per my knowledge, Voice over reads the accessibilityLabel, accessibilityHint, "text field is editing" when it is a textfield. There is no way to change this until you change the trait.
YOU can change the trait to UIAccessibilityTraitNone, so that it does not read as "textfield is editing".

Updating this question with some current advice.
It is not appropriate to override UIKit's default accessibility handling beyond the accessibility properties it provides. Use accessibilityLabel, accessibilityHint, accessibilityTraits, etc.
UITextField has built in accessibility and handles role and state information to provide a consistent and robust experience to VoiceOver users. You can suppress certain VoiceOver announcements using accessibilityTraits, but that does not mean that you should.
The most appropriate thing to do in such a situation is to simply set a suitable label:
myTextField.accessibilityLabel = "Code verification"
This will result in VoiceOver announcing, "Code verification, text field, is editing", which is what users will expect to hear.
Note that accessibilityHint can be turned off by users, so this property should not be used for essential messaging or information.

Related

XCode UITest will not give NSTextField keyboard focus

So I have a window appear by clicking on a menu item. Normally the the first textBox would gain immediate keyboard focus, but in the UITest nothing in the window gains keyboard focus (no focus ring). This is problematic becuase it stops me from typing into the textfield with textField.typeText("someText")
I have tried .click() on the window and on the textbox to try and give it focus but nothing seems to bring the window or textbox in focus.
Any help will be greatly appreciated
Example
MainMenu().menuItemForWindow.click() // Opens window
app.windows["windowTitle"].textFields["textBoxId"].click() // Clicks but field does not gain focus
app.windows["windowTitle"].textFields["textBoxId"].typeText("SomeText") // Is not typed into the textField
As a side note, I have verified that all the elements I am querying do actually exist.
EDIT:
I have gotten it to work by literally spamming typeText() until it changes the value of the given text box with something like
if let oldValue = textbox.value as? String {
var newValue: String? = oldValue
while newValue == oldValue {
textbox.typeText("a")
newValue = textbox.value as? String
}
//If we get here then we have edited the text box
textbox.typeText(XCUIDeleteKey) // Get rid of spam text
//TYpe what I want
//...
}
However this method is hacky and I can't really put a time out except from heuristics (roughly 15-30s) so I was hoping someone could help explain a better way of ensuring focus on the textbox or at least an explanation of what I am doing wrong originally. Any help would be greatly appreciated.
Here are two possible ideas for you:
Assign an Accessibility Id to the object you are trying to interact with, and try addressing it via the Accessibility Id. From https://blog.metova.com/guide-xcode-ui-test:
For element identification there is additionally elementMatchingPredicate(NSPredicate) and elementMatchingType(XCUIElementType, identifier: String?).
These are separate from containingPredicate(NSPredicate) and containingType(XCUIElementType, identifier: String?) which are checking the element for items inside it whereas the elementMatching... options are checking the values on the element itself. Finding the correct element will often include combinations of several query attributes.
Enable Accessibility in the System Preferences | Accessibility as described here: https://support.apple.com/en-us/HT204434 and then send keyboard commands to set your focus.

XCUITest - neither element nor descendant has keyboard focus

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.

How to alter title bar height for access form?

Is there a way of altering the title bar height for a form (actually a subform) when it is displayed in datasheet mode?
My field titles are often longer than the data and there is not very much I can do about this. It's not a problem when the form is in 'Single Form' view, but there will be lots of times when the datasheet view is helpful, because it's a good summary of info.
I had thought that forcing a new line in the field title might work, but it doesn't.
Access does not allow for this to be done. The standard way most Access developers circumnavigate this issue is to use labels. Set your DatasheetCaptions to blanks ("") and use labels as your column headers. This way you can multi-line them or format them however you want.

PPTX - Finding out whether text is bulleted from OpenXML

I have not been able to find any indicator which could tell me whether text in txBody tag is bulleted or not, can you please me in identifying which indicator should I use to understand whether the text is bulleted or plain ?
-Thank you
Inside the txBody tag, you can look for the tags "a:buFont" and "buChar" which helps you identify that the text is bulleted. eg.
<a:buFont typeface="Arial" pitchFamily="34" charset="0"/>
<a:buChar char="•"/>
Update:
Hi, +1 For posting this question, learnt a lot from it.
After googling I found this link which addresses similar issue, the resoponse from Adamm clears this,
"Ok, so i think ive got this figured out. Basically if no formatting
is specified in the layout or the slide, it goes to the master, and if
its a 'title' or 'ctrTitle' shape it uses the formatting in
and it defaults to lvl1. Same goes for text that is not
in a title shape, for these it defaults to the formatting in
and if no lvl is specified it defaults to lvl1. And
another piece of advice, although not pertinent to my original
question, there is another txStyle in the slideMaster,
which is used for text in a shape that is not in a txBody."
Now the slide in your pptx is using "Office Theme" and the text you are interested in is in the format shape within the slide design. The bulletted text is inheriting from the slideMaster1.xml in SlideMasters.
As mentioned in the above quote the buletted text is getting inherited from "a:lvl1pPr" of "p:bodyStyle" in the slideMaster1.xml, also you can see the level 2 bullet is defaulted to "-" for the office Theme slide master there.
I tried to confirm this by changing the char = "•" to ">" to see the bulleting changed to ">" in the below line
<p:bodyStyle>
<a:lvl1pPr marL="342900" indent="-342900" algn="l" defTabSz="914400" rtl="0" eaLnBrk="1" latinLnBrk="0" hangingPunct="1">
<a:spcBef>
<a:spcPct val="20000"/>
</a:spcBef>
<a:buFont typeface="Arial" pitchFamily="34" charset="0"/>
<a:buChar char="•"/>
....
Now if you want to change it programatically you can do this from slide master 1. But the only problem here is When we change the bulletted style here(like above), it is changing for all the slides and also for the future slides you will be creating with the same theme within your ppt.
Hope this helps.
Regards.

how can I show only number format input in UITextField?

I am making simple application that will take hotel name and price of item, and I want to show the price in only number format, because it can not be in alphabatical format, so what should I do add in code so that only number will be inputted in the Price UITextField?
If you are not getting my question, you may ask anything again
I do appreciate if I will get proper way of doing this,
If you want your text field to accept only the numbers, you can set it's keyboardType property to UIKeyboardTypeNumberPad.
[yourTextField setKeyboardType:UIKeyboardTypeNumberPad];
There are different types of keyboardTypes available, which you can refer in UITextInputTraits Protocol Reference.
This could be done in the Interface Builder as well: