How to keep the last character always visible in an input field on mobile safari? - jquery-mobile

I've a mobile web app and in it I've an input field type text.
I'm assigning it's value as
function setVal(str){
var item = $('#textField'),
string = item.val()+str;
item.val(string);
}
As the value is set programmaticaly without focusing on the field and typing on a keyboard, as the string gets longer than the width of the text-field, I can no longer see the new character additions as the text-field masks it.
You can see in the image above, the right most letter is 'K' (after j) but only part of it is visible.
How do I make sure that if the length of the string is more than the width of the text-field, the extra length goes left ward and the last letter is visible on the screen all the time?

Not exatly what you're looking for, but you can scroll left the text inside equally to the length of the input text, so the last character can always be visible.
var el = document.getElementById('textField');
el.focus();
el.scrollLeft = el.scrollWidth;
<input id="textField"></input>

Related

Set dynamically digits for EditText - Android

I want to limit an EditText field to English characters and numbers only.
I can do this in the xml section as follows
android:digits = "..."
and dynamically as follows;
editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
However, only a keyboard with numbers appears, so there is no clickable letter but digits work correctly (I tested with copy paste).
Problem: Both the letter and the number should appear on the keyboard.
editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
editText.inputType = InputType.TYPE_CLASS_TEXT
I tried this but it loses its DigitsKeyListener feature.
Solution
editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
editText.setRawInputType(InputType.TYPE_CLASS_TEXT)

Array item completion in a UITextView

I'm trying to accomplish an autocomplete of my own for matching array items while typing. So, I already have the logic done for matching what's being typed with what's in the array, but my question is related to displaying the proposed correction in the UITextView like this screenshot
I was trying by splitting the text in the textview and replacing the last word into attributed strings, but that makes the proposed correction part of the actual contents. Any ideas of how this is accomplished in this app?
What you currently do is good , when you set the text of the textView to attributed string make bool flag say it's name is textEdited = true with a string part that the user types say it's name userStr , when textView change method is triggered check that bool and according to it make the search if it's true proceed search with userStr if it's not proceed search with whole textView text , don't forget to make textEdited= false after every zero suggested result
Edit: regarding the cursor put a label under the textfield with the same font as the textView and make it's background darkGray , also make background of the textview transparent and every attributed string assign it to the label so plus part of the label will be shown and cursor will be as it is in the textView

Can i replace the period in decimal pad with a comma in Swift 2 iPhone app?

Or maybe add a comma on the number pad without creating a custom keyboard.
I tried changing NSLocale to to another country but that didn't work. I have a function that separates multiple numbers from textFiled to evaluate them separately separated by commas but the keyboards do not contain a comma and i would rather not use the numbers and punctuation keyboard for this. Any help is appreciated. Using Xcode 7.2.
You can't change the keys on any of the built-in keyboards.
You can create your own keyboard view with the inputs you want (numbers, the comma, backspace) and set it as the inputView of your text field. The system will display your keyboard view instead of a standard keyboard when your text field becomes first responder.
Or you can just create, say, a toolbar with a comma button on it, and set the toolbar as your text field's inputAccessoryView, and let the text field use the standard decimal pad for numbers and backspace. The system will display your input accessory view above the standard keyboard when your text field becomes first responder.
Read “Input Views and Input Accessory Views” in the Text Programming Guide for iOS.

No text is pasted when text is longer than max length in iOS

I am trying to paste a longer text in a textfield, longer than the defined maximum length. However no text is pasted. Is this a default behavior in iOS?
Thanks
The default behavior is (to quote the documentation):
YES if the specified text range should be replaced; otherwise, NO to keep the old text.
So, as you can see, returning NO means that the text will not change.

Insert string at cursor position of UITextField

I've got a few UITextFields in an UITableView. The user should be able to insert only numbers and dots. To do this, I set the keyboard type to UIKeyboardTypeNumberPad and added a '.'-Button at the bottom left corner. Every time the button is pressed, a function is called. This function should insert a dot at the current cursor position, but this is the problem: UITextField hasn't got an selectedRange property, so I'm not able to get the current cursor position. Does anybody know how to solve this problem or is there any other way to do this? Thanks.
I've finally found a solution for this problem! You can put the text you need inserted into the system pasteboard and then paste it at the current cursor position:
[myTextField paste:self]
I found the solution on this person's blog:
http://dev.ragfield.com/2009/09/insert-text-at-current-cursor-location.html
The paste functionality is OS V3.0 specific, but I've tested it and it works fine for me with a custom keyboard.
Update: As per Jasarien's comment below, it is good practice to save off the pasteboard contents first and restore them afterward. For convenience, here is my code:
// Get a reference to the system pasteboard
UIPasteboard* lPasteBoard = [UIPasteboard generalPasteboard];
// Save the current pasteboard contents so we can restore them later
NSArray* lPasteBoardItems = [lPasteBoard.items copy];
// Update the system pasteboard with my string
lPasteBoard.string = #"-";
// Paste the pasteboard contents at current cursor location
[myUIField paste:self];
// Restore original pasteboard contents
lPasteBoard.items = lPasteBoardItems;
[lPasteBoardItems release];
- (void)insertText:(NSString *)text
available in iOS 3.2 and later.
In Swift
This inserts text at the current cursor position.
textField.insertText("Hello")
My full answer about working with the cursor position is here.
There is now a fantastic number pad type keyboard that includes a decimal point, no configuration necessary except setting (not in IB, not an option there yet) the UITextField's keyboardType property to UIKeyboardStyleDecimalPad, like so:
textField.keyboardType = UIKeyboardTypeDecimalPad;
This does all the fancy stuff you've been trying to do automatically.
If you're looking to create text fields that allow you to enter decimal places may I suggest that you rather fix the decimal point to a certain precision and allow the user to enter numbers as follows:
Assuming your precision is 2 decimal points:
start: value is 0.00
user enters 1: value is 0.01
user enters 2: value is 0.12
user enters 3: value is 1.23
user enters 4: value is 12.34
See What is the best way to enter numeric values with decimal points? for a similar solution for currency.
It is by far a more simple solution than creating a custom keyboard and dealing with all the nuances that that approach presents. If, however, you need variable length precision then that approach might suite you better.
Read the value of the text field as a string when your button is pressed. Edit the string and then set the value of the field to the new string.

Resources