Multi-Tag Auto Complete Textfield in Apple iOS development with Swift - ios

So far I could accomplish Auto Complete feature on a Textfield UI in Xcode 6 for my iOS app, but my challenge is to make it take multiple tags and then show suggestion for each one. For example:
Enter "Ja" and it shows "Java" in the list, I choose that, type "," and it make it a tag, then I start typing "PH" and it shows "PHP", and I choose that and place another "," and so on. Just like the Jquery Auto-complete for multiple tags. Is there a way to accomplish this in iOS ?
Link to Jquery AutoComplete Plugin

Use WSTagField library by whitesmith
Since you have completed the autocompletion logic. You just need to show the results in a UITableView. Then use WSTagField as shown below to show/hide suggestions table view.
let tagsField = WSTagsField()
// Events
tagsField.onDidAddTag = { field, tag in
//Remove suggestions tableview from the view
print("DidAddTag", tag.text)
}
tagsField.onDidChangeText = { _, text in
//Add suggestions table to the view
}
tagsField.onDidChangeHeightTo = { _, height in
//Update suggestions table frame to prevent tag field covering
}
tagsField.onValidateTag = { tag, tags in
// validate tag here to match your tags list
}

Related

how to toggle using multiple buttons and pass info to the output JQuery

JQUERY CODE:
$('#selector button').click(function() {
$(this).addClass('active').siblings().removeClass('active');
$('#gaga').toggle
})
PUG CODE FOR #gaga element:
p#gaga
| This is `${Value}`
PUG CODE FOR #gaga element:
How can I use three buttons to toggle the #gaga element on when button is active and off when you click outside the specific button and pass a different Value for ${Value} depending on the clicked button. Plus have only one instance of #gaga element running at a time. Meaning if I click the first button then click the second button only the ${Value} will change but the p#gaga element remains only one. I know I have left out the buttons pug code, I don't think it is necessary in solving the problem. But if needed will provide it.
I tried doing it using switch statements but I have failed. Hopefully someone can help.
UPDATE & EDIT as requested by https://stackoverflow.com/users/463319/twisty in the comments.
Here is the code: https://jsfiddle.net/YulePale/mdvnf0qt/4/
After doing some research I have made some progress... but I am still stuck.
I am trying to make it in such a way that when I click anywhere outside the gender buttons the input disappears and when I click another button it changes appropriately. Also instead of an input I want to show and hide the template in the html code.
Also, if you don't mind is .data() use to assign or get a value.
PS: Got this code from this answer : Fixing toggle with two buttons
and modified it a bit, but I am still not able to achieve my desired result.
If you review the API for Menu, they have a nice _closeOnDocumentClick(). You can simply use this in your code in a similar way.
Example: https://jsfiddle.net/Twisty/0x43bf8q/
JavaScript
$(function() {
$("input[type='button']").on('click', toggleOptions)
.first()
.trigger('click');
$(document).on("click", function(e) {
if (emptyOnDocumentClick(e)) {
$('[name=gender]').val("");
}
});
function toggleOptions() {
var $this = $(this),
onClass = 'button-toggle-on';
$this.toggleClass(onClass)
.siblings('input[type=button]')
.removeClass(onClass);
var gender = $this.filter('.' + onClass).data('gender');
$('[name=gender]').val(gender);
}
function emptyOnDocumentClick(event) {
return !$(event.target).closest("input[type='button']").length;
}
});
Hope that helps.

How would you go about disabling a button as long as 2 text fields are empty in Objective C?

I have a view controller that controls 2 text fields and an array that displays in a table. How would I go about keeping a button disabled until the 2 fields have at least one character and the array is not empty. I am thinking about using cocoa bindings, however I can't seem to figure out a solution.
Currently my button is binded to
BOOL buttonIsEnabled;
I use that in a notification function in order to keep the button disabled, except the button will only reenable if I call that notification function.
-(void)controlTextDidChange
This means if i make a change in an array, the button wont reenable until I re-enter text. I can't seem to figure out an alternative solution. Any suggestions? Thank you.
One solution:
bind the two text fields two two strings (say text1 and text2)
in the text field bindings check Continuously Updates Value
Add this code:
- (BOOL)buttonIsEnabled {
return (self.text1.length>0 && self.text2.length>0);
}
+ (NSSet *)keyPathsForValuesAffectingButtonIsEnabled {
return [NSSet setWithObjects:#"text1",#"text2",nil];
}
Lastly bind the buttons enabled binding to buttonIsEnabled.
Because of the Continuously Updates Value text1 or text2 will change whenever characters are added to or removed from the text fields.
And the + (NSSet *)keyPathsForValuesAffectingButtonIsEnabled method will cause a Key-Value change notification to be posted for buttonIsEnabled whenever text1 or text2 change.
You can create a custom cell, give outlets to your 2 textfields and button.
Now on cell for row at index path after filling the textfields text values, put a condition checking the length of the textfields. If length is greater than 0 you can enable the button or keep it disable.
Along with this you need to put same code in delegate method (textFieldDidChange) of textfield. So that when ever new text is entered the button gets enable or disabled.

Getting values out of text fields with UIAutomation

I'm trying to understand how UIAutomation can be used to perform automatic application tests, so I've created a temperature converter app that can be driven from the JavaScript interface. Here's the UI:
The top text field has an Accessibility label of "Celsius", similarly the bottom field has "Fahrenheit" as its Accessibility label. I'm trying to drive it through this script:
UIALogger.logStart("Test -40ºC == -40ºF");
var window = UIATarget.localTarget().frontMostApp().mainWindow();
var celsiusField = window.textFields()["Celsius"];
var fahrenheitField = window.textFields()["Fahrenheit"];
var convertButton = window.buttons()["Convert"];
celsiusField.setValue("-40");
convertButton.tap();
var fahrenheitValue = fahrenheitField.value();
if (fahrenheitValue == "-40.0") {
UIALogger.logPass("-40C == -40F");
} else {
UIALogger.logFail("-40C == " + fahrenheitValue + "F");
}
This correctly sets the text in the Celsius field to "-40", and when the button is tapped, the app updates the text in the Fahrenheit field to "-40.0". However, fahrenheitValue has the value "Fahrenheit" (the name/label of the text field), so the test fails. I wondered whether this was maybe a timing issue, so put in a one-second delay after the tap, which didn't change the behaviour.
Is it possible to get the text out of the text field and compare it with the expected value?
Is it getting "Fahrenheit" because that's the accessibility label or because it's the placeholder text?
It looks like value() might return the placeholder text. One workaround could be to modify the placeholder value once the user starts typing to set it to be the text the user entered and then reverting it to Fahrenheit when they delete? I assume that even when you call setValue it acts as it would when the UITextField delegate methods get called?
You could add a label to your view, update it and read it out.
Try hooking up the Accessibility Inspector to show what UIAutomation "sees" in your app. It might be that it's reading some stale values because of the way you set the values in your app.
One way of refreshing the values is to send an update event:
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);

Removing highlighting of text in text box after switching tabs in jquery-ui-tabs

I am experiencing a weird issue with the jquery-ui tab object. If I highlight the text of an html input tag (type="text") that is on a tab, switch tabs, then come back to the original tab, this text is still highlighted. I can actually remove the highlighting before switching tabs, and when I come back, the text has been highlighted again. I have tried to remove this highlighting by calling .blur() on the textbox after the show event of the tab is triggered, but this does not work. Similarly, actually clicking on other parts of the page (which I take blur() to be the equivalent of) does not remove the highlighting of the text. Is there something else I could be doing here?
Thanks.
I have solved the issue at hand by modifying the selectionStart property of the input DOM object. By setting it equal to the selectionEnd property, you ensure no text is highlighted. The selectionStart property was being changed on my original highlighting, so when I came back to the tab, the text was re-highlighted. Solution below.
$(this).find('input').each(function () {
var input = document.getElementById($(this).attr("id"));
try {
input.selectionStart = input.selectionEnd;
}
catch (err) {
}
});

MVC toggle buttons

I have a group of buttons at the moment which users can select to filter out a grid. The problem is that after one of the buttons is clicked, the user does not know the current active filter that was applied. So can anybody help me to figure out how to have these group of buttons act as toggle buttons (spec is to change the button background color for active button)?
Please note this is in MVC and there is an onclick event bound to each of the buttons which calls a javascript function.
If you ar using jquery UI you could try using the button plugin configured as a checkbox
You haven't given much detail on how you've wired up click events, but in your click handler for the buttons, you could do something like this:
var button = document.getElementById("button");
button.onclick = function() {
if (!this.style.backgroundColor) {
this.style.backgroundColor = 'yellow';
}
else {
this.style.backgroundColor = null;
}
}
There are other ways to do this if you're using jQuery or another JS framework.

Resources