I've got a textfield, which is using a numberpad for input, and I'd like to make it so that when the user types in a number, the textfield automatically inserts an ' (apostrophe) after the first digit, and any other numbers would follow the apostrophe. But to make this noticeable, I'd like to have the apostrophe 'pop up' with a change of color, before resting in the textfield. Much like the action of the keyboard letters when they're hit - they pop out for a second.
Seems to me there's several things to be done and I haven't found any help online with them:
Get notice after one digit is entered (more than one digit could be entered, but the animation would take place and the additional numbers would show up after the apostrophe).
Add the apostrophe into the textfield.
Animate the insertion of the apostrophe, while allowing the textfield to continually take in input.
Any direction to libraries or code or suggestions would be immensely appreciated. Thank you so much. I've a hunch I'm supposed to use coco2d but have no idea how to get started.
I figured out a work around that I'd thought I'd share in case anyone is interested. For monitoring input, you can use:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
which gets called when the user touches the keyboard, but before the character or number is processed and put to screen. The only problem is that on an empty text field, if the user hits backspace this method doesn't get called (even if not null). Basically because there's no change to an empty text field to process with an empty string.
You could also use: UITextFieldTextDidChangeNotification, but it gets called in the same way and doesn't offer any parameters to play with.
For 2: I ended up making labels for these and putting them over the text field where I wanted, and playing with their properties as needed. It was kind of messy so I actually split the text field into 2 and used the above method to jump in between. Seems to work mostly well, but dealing with the backspace issue is still unsolved (how to move back to the first text field when backspacing through text for example). Am considering overlaying a transparent button on that part of the keyboard. Seems messy though. I would appreciate any cleaner ideas that are out there.
So, didn't end up doing any animations, which would have been a much slicker. Hope this helps.
Related
I want to add a line counter to a textfield for a sort of text editor. Looking around, I've seen that a lot of questions on this topic are either unanswered, or do not answer in a satisfactory manner. Something like this How to add prefix widget on every new line in textfield in flutter? asks fundamentally the same question I am, however the only answer there is to create a new widget for each line.
This is one method that could be used, where I add new textfields in a list and build them in a row with their respective line number. However, this means I cannot have those textfields function on more than one line, and I will need to add more textfields each time a user wants to add enough text to make it overflow. The biggest flaw I see with this, though, is that it makes it harder (if not impossible?) to easily select and edit text as you would expect from a text editor, such as using the built in systems for a textfield.
Now, for my solution I am using https://pub.dev/packages/extended_text_field as a way to gain some functionality that I don't really want to take the time to figure out how to do on my own (embedded onClick callbacks for text), so it would be ideal if I could continue to use that without having to fork or even have to figure out how to write my own version.
The primary issue I'm running into is not necessarily getting the number of lines, which can be found using some solutions from How can I add line numbers to TextField on Flutter?, but rather how and where to show those line numbers.
As above, it's not really ideal to pair some number alongside a textfield and create a new textfield for each expected line. What would be ideal, however, is something like , where each line number is prefixed to the line built by the text field. For example, like this: . Something like the solution proposed in Add a prefix to every line in a multiline Text Input in Flutter? would not work especially well, because the solution there is to literally add string values to the textfield, which would require systems to clean the text, in addition to causing an unexpected ability to actually change the numbers (or other line prefix) by the user.
So -- is there any way to implement a line prefix for each line in a textfield? Would it be possible to override an InputDecoration (which allows creating the individual line prefix, but nothing more) to create a line prefix for each line drawn by the textfield? If not, exactly what would be needed to create this? I am familiar with flutter, but I am not quite as familiar with the lower level API's.
So I am having a problem. This is what I can create on one of my laptop:
On another, when I created something that has {TC} in it, the whole field code disappeared.
For the example above, if on the other computer, both are running Office 2010,
I can input the code to create the table of content from:
{TOC \f \h \z \f 1\t "Heading 1,1,Heading 2,2,Heading 3,3,Title,1}
to
{TC}
The moment I type in TC, the whole {} disappears.
Other field codes work just fine, except for {TC}. So my question is how do I get {TC} to show on my other laptop?
Thank you for your time.
Apparently, I found my answer.
When I searched google for my answer, most sites give this as a solution:
For Word 2010, go to File->Options->Advanced
Under Show document contents: Select "Show field code instead of their values"
This is the equivalent of pressing Alt+F9, which DID NOT solve my problem.
Apparently, the solution to get {TC} to show in your document is in:
go to File->Options->Display
and check to always show HIDDEN TEXT.
I hope this helps someone in the future.
Yeah, the disappearing TC code is annoying at first -- seems like it's broken. Other codes work, but why does that disappear, even if entering manually? Word instantly sets TC code to Hidden, even the field code itself.
To temporarily toggle this visible without permanently changing your display to show Hidden Text, you can use the normal Ctrl-Shift-8, which toggles display of spaces, paragraph marks, tabs, and Hidden Text, on and off. This is a good keyboard shortcut to have in your standard back of tricks anyway. It is frequent in Word that you need to toggle paragraph marks on and off, because paragraph formatting is attached to the Paragraph mark, and when they're hidden, it can be tricky to fix various formatting issues.
The original post was a few years ago, but I fear things have gotten worse since then, not better. I am using Word 365 v2201, which should be up to date. The other day, I wasted hours on trying to resolve this issue with TC field codes.
First I tried entering them using Insert > Quick Parts > Field. Word creates what looks like a field code, but it behaves as normal text. Messing around with the various controls to toggle field display and hidden text etc etc, has absolutely no effect. It is basically a faux field. And of course, it is completely ignored when compiling the TOC.
Next, I tried entering it manually, by using Ctrl + F9 to either create a blank field or convert some existing text into a field. Same result as above.
As with the original post, this seems to afflict only the TC field code. Other codes work fine, including TOC. And if I create a TOC field, then edit the code to TC, it immediately loses its properties as a field. If I then put the O back in, it immediately behaves as a field once again. Unlike in the original post, adjusting the settings for field display and/or hidden text, have no impact.
In the end, the only solution was to create the field using Alt + Shift + o to open the Mark Table of Contents Entry dialog box. And finally, this works!
I am trying to simulate Word's displaying of non-printing characters. There is no problem with all of them but anchors and I didn't found any info related to them. Is anchor special character placed in text or is it parameter of floating object and just displayed as special character?
Thank you for answer
The anchor, unlike most non-printing characters, can never print. It's merely a visual aid to inform the user with which paragraph or character a graphic with text flow formatting is associated. It's not possible to detect an anchor directly in the document text using Word's API (object model). It's bound to the graphic and would require analyzing the properties of the Shape object.
It could be determined by analyzing the document's WordOpenXML, although the term "anchor" is not used. The information could be deduced from the location and settings of the nodes that define where and how the graphic appears.
Is anchor special character placed in text or is it parameter of floating object and just displayed as special character?
I'm going to try to answer the "is it in text" question.
If, while debugging, you try to get a textual character for an anchor from a range's text, it won't be there. There won't even be a 0-width non-visible character there, like when you move a text cursor to the right past a non-printable character, but it doesn't actually move because there's something there (this may be editor-dependent, I have Notepad++ in mind).
So no, it's not in text.
But, at the same time, it will interfere with searches. E.g. If you put the word "text" on a line, put a text box on that line to create an anchor, and then search for "^13text" (with wildcards enabled, ^13 means the end-of-paragraph mark), it won't find it.
So yes, it must be in text because it interferes with searches.
So this might be a contradiction, but let's keep going. If it's in text, where is it? If you place the text cursor on the previous line, hold shift, and move it once to the right, the text box will be highlighted.
So it must be at the start.
But, there is also evidence that contradicts this. If you have a field at the start of the line with text on it, you can move it once to the right as before, and then once to the left, and though you have part of the line highlighted, the text box won't be part of the selection.
So, I really have no idea whether it's text or not, or where it is if so, but hopefully this helps someone else.
So I am using selectedTextRange to get a cursor position from my UITextField. I would like to obtain a substring from the beginning of my TextField text up to the cursor position. How would I go about doing this? I am able to create the UITextRange I want but I don't know how to use this to get the actual substring since substringWithRange seems to only work with NSRange. Any guidance would be greatly appreciated.
You need to use the methods from the UITextInput protocol, which is implemented by all text views, to do this. With a text range, you can simply call textInRange: to get the text.
To get the text from the beginning of the field up to the selected position, you'll need to make a text range first with textRangeFromPosition:toPosition:, passing beginningOfDocument for the first argument, and the start of your text range for the second argument.
I have a text field that is always of the format "XX0000000XX", X being a letter, 0 being a number. I switch keyboards as the user is typing depending on whether they need to enter a number or letter.
This works fine, until the user positions the cursor in the middle of the text field to make an edit. How do I determine the cursor position within a UITextField?
I know a UITextView has a selectedRange that can be used, but I've read that you can't force a UITextView to be single line entry? i.e. Disable multiple lines of text.
Clever bit with the keyboards. My immediate thought is that perhaps that you shouldn't allow the user to move the cursor in the first place.
This isn't without precedent in the iPhone UI. The telephone keypad view, for example, restricts the user to sequential input. I have also found this technique useful for currency input. Anywhere with input that has a very rigid syntax, basically, seems like a candidate for this kind of treatment. Might work well for your situation.
Not sure if this is the best method, but here's how I do it:
A UITextField to capture input and a UILabel to display the input. The text field is hidden but is sent becomeFirstResponder to trigger the keyboard. As the user types, delegate methods do their thing to format the text, if necessary (as with currency), and update the UILabel, which provides the user feedback on their input.
Depending upon the situation, you may wish to style the UILabel in such a way that makes it clear the user can't use it as they would a selectable text field while reassuring them that it is, in fact, their input.
With 11 characters in play, I can see how curser editing might be useful. Still, phone numbers are often in that same range and I never have a problem with the sequential editor in the Phone app.
There's a UITextDelegate method -textField:shouldChangeCharactersInRange:replacementString: which should be all you need to do what you describe. Implement it to enforce whatever formatting rules you want. You shouldn't care where the cursor is, just the range of the change that's proposed.