dojox.mobile.SearchBox does not work properly - ios

I'm using dojox.mobile.SearchBox in Worklight project.
I found out 2 issues.
The first is that the clear button(a small cross in a circle, which must to clear the text in the search box) does not work on the IOS Safari(or in the workilght app which uses safari).
The only thing happens is that the cursor moves to right side of the text are in the search box. That's it. It does not remove the text.
And the second one.
I need to call function by pressing search button on the virtual keybord.
If I set the type="search" in search box - there is no search button on the keybord.
So i put my search button into the .
So search button appears on the virtual keybord.
But after the pressing this button, the form submits and I page reloads.
And I just need to call a function.

I've resolved both issues))
1) About event on pressing Search button(enter)
There is an issue in IOS Safari with appearing "Search button" on virtual keybord.
your text input with type="search" must be inside form tag.
Show 'Search' button in iPhone/iPad Safari keyboard
(second answer)
To call some function on pressing Search button and not submit a form I put the following javascript into the from tag:
<form onsubmit="myFunction(...);return false;">
Pressing Search button starts the Submit action. And this javascript call my function at this time and stop the submitting. That's what I need!
2)
The second problem with clear button of the search box.
This is the bug of dojo. https://bugs.dojotoolkit.org/ticket/16672
I've found a workaround. http://dojo-toolkit.33424.n3.nabble.com/dojox-mobile-SearchBox-Clear-Button-x-fails-in-iPad-iOS-16672-td3995707.html
But I change it a little, cause it does not work in my case.
This is the my variant:
<form onsubmit="myFunction(...);return false;">
<input id="searchBox" ontouchstart="clearButtonSupport(event);" data-dojo-type="dojox.mobile.SearchBox"
data-dojo-props="type:'search'" type="search"
placeholder="Some placeholder...">
</form>
This is the clearButtonSupport function:
function clearButtonSupport(evt) {
require([ "dijit/registry", "dojox/mobile/SearchBox" ], function(registry) {
var searchBox = registry.byId('searchBox');
var rect = document.getElementById('searchBox').getBoundingClientRect();
// if touched in the right-most 20 pels of the search box
if (rect.right - evt.touches[0].clientX < 20) {
evt.preventDefault();
searchBox.set("value", "");
}
});
}
onclick and onmouseup event in IOS safari works only when text input is not focused.
If the focus on the search box(cursor is inside) this event is not thrown.
So i used ontouchstart event
ontouchstart - multitouch event in IOS safari.
It's thrown every time you touch the element.
So I take the coordinates of the first(and the only) touch.
And look if it's less than 20px far away from the right side of the element.()position of the clear button)
And clear the search box.
That's it!

Related

MdAutocomplete AngularJs on iphone doesn't focus input and keyboard briefly popups up. Seems when you hold down on the input the keyboard comes up

I have an md-autocomplete component pretty box standard :
<md-autocomplete
id="address-autocomplete"
md-input-name="postcodeInput"
md-input-id="postcode-input"
md-input-class="md-input form-control postcode-form-control"
md-selected-item-change="vm.selectedAddressChange(item)"
md-search-text="vm.postcodeQuery"
md-search-text-change="vm.postcodeQueryChange()"
md-item-text="item.Text"
md-min-length="0"
md-items="item in vm.addresses"
md-no-float
md-no-cache="true"
md-clear-button="false"
placeholder="Postcode"
>
<md-item-template>
<span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">{{item.Text}}</span>
</md-item-template>
<div ng-messages="vm.addressForm.postcodeInput.$error">
<div ng-message="required">This field is required</div>
<div ng-message="validFormat">Please enter a valid postcode</div>
</div>
</md-autocomplete>
However on iphone 13 [maybe other iOs devices]. When I tap on the input field the keyboard starts to come into view and goes away as I lift my finger. If I hold my finger down on the input the keyboard stays, but the input doesn't focus and so the keyboard again goes away. However, if you even slightly move your finger, the input focuses and the keyboard sticks.
I'm not sure if anyone else has this issue, but I've checked the debugger and inspected the element and added breakpoints when attributes change. Not helping because I assume there's something happening async (timeout) that causes this, so when it pauses I don't have this issue.
Tried to add my own custom handlers and still can't get it to work. To hack the MdAutoCompleteCtrl.

JQuery Mobile - select onchange breaks tabbing to next field

When using Jquery mobile, When you select an option from a select with the keyboard, you cannot tab to the next input in the DOM. If you take out the jquery mobile bits, things work as expected.
I have the following html:
<body>
<input type='text' id='starter' /><br />
<select id='sel'>
<option value=''></option>
<option value='1'>One</option>
<option value='2'>Two</option>
</select><br />
<input type='text' id='ender' /><br />
</body>
I have set this up on fiddler with jquery and jquery mobile below:
http://jsfiddle.net/58jkj1wa/ - raw jquery works as expected.
http://jsfiddle.net/a5reojmo/4/ - jquery mobile broken select.
To reproduce the issue perform the following:
The cursor starts in the first input
press 'tab' to move to the select
press down arrow to activate the options
press down arrow to select the first option
press return to accept the change (non mobile - focus is now correctly on the select)
press tab
In the non-mobile version the cursor is now in the second input as expected. In the mobile version it's someplace else... and I don't know where. You have tab a lot for the focus to move to the first input again... then through the inputs to the field you want after the select you just used.
Personally I reckon this is a bug, so the most interfering I felt prepared to do was to try the on change trigger to try and set the focus back to the select like this:
$("#sel").on("change", function (e) {
$("#sel").focus();
});
But this does not work. If you do the focus call anywhere else, it works as expected, highlighting correctly and tabbing off if you do not change the value. but as soon as you change the value the focus is someplace else.
I can set the focus to the next item however:
$("#sel").on("change", function (e) {
$("#ender").focus();
});
But I'd rather not do this as this means I can't do some of the dynamic hiding of inputs I'm doing and have to programmatically mirror the flow handling in the form.
I've tried updating some of wrapper stuff that JQM adds and I've tried setting focus on another input and then back again, and then optionally doing a selectmenu refresh, but the mobile still can't tab out to the next input. I've also tried various blur() and focus() calls all to no avail.
I did see this answer doing something similar by adding a keydown handler, but since I don't know where the focus is after a value change I don't know where to add the keydown handler... besides this sounds like a JQuery Mobile bug doesn't it??
Do you know how I can make tab and focus-highlight work correctly after a select change in JQuery Mobile?
Is this a bug I should report?

Jquery mobile radio button not always setting the underlying input on click

I have a jqm radio button that looks like this:
<div data-role="controlgroup" data-type="horizontal">
<h3>Type</h3>
<input type="radio" name="type" id="deposit_typeTotal" value="t" checked/>
<label for="deposit_typeTotal">Total</label>
<input type="radio" name="type" id="deposit_typeIndividual" value="i"/>
<label for="deposit_typeIndividual">Individual</label>
</div>
It's part of a phonegap application which I'm currently testing on an android galaxy s2, which is where I'm seeing the problem. I've never been able to get it to break in Google Chrome on the desktop.
I have an click event attached to this button which calls a function which does various things, but I've modified it to alter the title to the value of the button to aid my debugging.
var type = $("#deposit input[name=type]:checked").val(); // Gets the value of the checked button
app.count++;$(".depositOrPayment").html(app.count+"/"+type); // Sets the title of the page
So what I'm seeing is the number of times the function has been called / t or i depending on which button I click. However, sometimes (particularly if I click the buttons quickly) I get undefined as the button's value. Once this happens, it stays as undefined no matter how many clicks I do.
Anybody got any ideas?
Cheers
Graham
There is a difference between click and tap. A tap has about a 300ms delay (around that). Anyway, you can also bind to the tap & click event in JQM (virtual mouse events).
$('#element').on('tap', function() {
...
});
or
$('#element').on('click tap', function() {
...
});
Read this: http://phonegap-tips.com/articles/fast-touch-event-handling-eliminate-click-delay.html
So there is FastClick https://github.com/ftlabs/fastclick
Check this out What is the difference between the click and tap events?
And this http://phonegap-tips.com/articles/fast-touch-event-handling-eliminate-click-delay.html
EDIT: I made this a wiki in the hopes that someone can answer it better than me :)

IBM Worklight 6.1 - How to detect the keyboard's "Search" button?

We are developing a hybrid mobile app using IBM Worklight 6.1.
For iOS, how to handle "Search" button event from the soft keypad that is displayed?
"handle" is a bit vague... What are you trying to accomplish?
You shouldn't need to detect any button, if you invoke the correct keyboard for the specific need.
The search button in the iOS keyboard will only appear if your input tag is inside a form element.
For example:
// This will display a return button.
<input id="textField" type="text"/>
// This will display a search button.
<form>
<input id="searchField" type="search"/>
</form>
In JavaScript, you can use the jQuery keypress event to trigger an action once the search button is tapped. For example:
$("#searchField").keypress(function() {
alert("Handler for .keypress() called.");
});
You could also "detect" the "type" of the keyboard, in the case of "search", like the following (but this is kinda obvious...):
if ($("#searchField").attr("type") == "search") {
alert("This search field is of type 'search'.");
}
Otherwise, you will need to implement native code (meaning a Cordova plug-in) to detect the type of the currently displayed keyboard and perform actions, etc...

Tap Click whatever finger motion event on iPhone 3GS

All I want to do is capture the event that a user taps an and clear it. I can't get anything to work with iPhone 3GS.. There is barely any documentation on how to actually use jQuery mobile.. that I can find anyway.. so theese are my guesses mostly:
$("#wrap").live('pageinit', function() {
$('#search_field').live('tap',function(event) {
if ($(this).val() == "Search Applications") {
$(this).val('');
}
});
});
This borks my design and adds a "loading" header at the bottom of the page....
Edit: Seems like it randomly works on the 3GS but the most annoying is that just jQuery mobile destroys my site layout!! my submit button jumps down
()
just looking over you code are you trying to use a place holder and clear it if the user taps it? If so you can simply add an attribute to your HTML5 like this:
<imput type="text" placeholder="Search Applications" />
Live example:
http://jsfiddle.net/KVuvm/
http://jsfiddle.net/KVuvm/1/ (With jQM Look and Feel)
http://jsfiddle.net/KVuvm/14/ (if you still wanted to use JS)

Resources