Click event won't fire on click on iOS devices but works as intended on desktop - ios

I am having trouble having my React application to work optimally on mobile Safari. My app will PUT, POST, PATCH, and DELETE normally on desktop but won't do so on my iPhone. I've tried adding "cursor:pointer" and onTouchStart to my React component below but nothing seems to be doing the trick.
onSubmit(event) {
const name = this.state.name;
const instructor = cookies.get('instructor')._id;
this.setState({
submitted: true,
});
this.props.dispatch(actions.editCourse(name,this.props.match.params.cuid));
}
render() {
if (this.state.submitted) {
window.location.href = `https://young-mountain-65748.herokuapp.com /courses/${this.props.match.params.cuid}`;
}
return (
<div className="container">
<div className="field-line">
<label htmlFor="coursename">New Course Name:</label>
<input
id="coursename"
name="coursename"
value={this.state.name}
onChange={this.updateName}
/>
</div>
</div>
<div className="edit-course-buttons">
<button
className="edit-course"
onClick={this.onSubmit}
onTouchStart={this.onSubmit}>
Edit Course
</button>
</div>
</div>
);
}
}

I too had the same issue on iOS devices. Was able to get over these by replacing onClick with touch events. Check this documentation on touch events in ReactJS. You may use onTouchStart instead of onClick and see if it works! So your button should look like this:
<button onTouchStart="{this.onSubmit}" onclick = "void(0)" ...>
</button>
I have added onClick as suggested in an accepted answer here.
https://facebook.github.io/react/docs/events.html#touch-events
Check the similar question, as per the answer most voted you need to use touchevent and add cursor: pointer; css to elemnt you have click event associated with.

Related

In angular 7, can you have multiple event emitters passed into one component?

In my signature component, I am trying to pass two event emitters, and eventually a 3rd event emitter into it.
When there is one event emitter, it works as expected, when i have two event emitters none of the expected behavior is happening.
In my parent component,
<div>
<app-signature
(checkSubmitFlagForFirstSubmitEvent)=
"receiveCheckSubmitFlagForFirstSubmit($event)"
(myEvent)="confirmation.getStudentQuestionsData()"
></app-signature>
</div>
<div class="tab-pane fade show" id="confirmation" role="tabpanel" aria-
labelledby="cada-form-confirmation-tab">
<app-confirmation #confirmation></app-confirmation>
</div>
Am I missing something obvious here? For the (myEvent)="confirmation.getStudentQuestionsData()", when the user clicks a button on the signature component, it should call a function from the confirmation component.
In my signature component TS file:
#Output() myEvent = new EventEmitter();
function2() {
this.myEvent.emit(null)
}
In my signature component HTML file, I have a modal that pops up, when they click OK on the modal button, it should call a function from my confirmation component:
<button type="button" class="close text-light" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" (click)="closeModal('submit-wait'); function2()">×</span>
</button>
In my confirmation component TS file, I'm trying to call the function getStudentQuestionsData() when the user clicks on a button from the signature component.
I am also calling it onInit, i dont think thats the cause of the issue though. I need the data when the app loads, and then when the user clicks on a button from signature component, it should call getStudentQuestionsData() again to refresh the data on the confirmation component.
ngOnInit() {
this.getStudentQuestionsData();
}
getStudentQuestionsData() {
'calling some API'
}
Currently your click event is inside of the span inside of the button. While your span is clicked it must not be bubbling the event up.
If you bind to the click event directly on the button it should start working better for you.
<button type="button" class="close text-light" data-dismiss="modal" aria-label="Close" (click)="closeModal('submit-wait'); function2()">
<span aria-hidden="true" >×</span>
</button>

Material Design Lite and dialog-polyfill modal dialogs on iOS

I'm using Material Design Lite (http://getmdl.io) along with dialog-polyfill (https://github.com/GoogleChrome/dialog-polyfill) for the modal dialog boxes.
Everything works great on my desktop browsers (Chrome, Safari, etc.), but on iOS (both Chrome and Safari), I can't tap inside the modal dialog boxes. It just doesn't respond.
I've tried the suggestion I've seen posted several places to put "cursor: pointer" in the CSS, but either I'm not doing it correctly, or it's not working.
Here's a typical modal dialog from my code:
<dialog class="mdl-dialog" id="delete_alias_confirm_dialog">
<h4 class="mdl-dialog__title">
Delete alias
</h4>
<div class="mdl-dialog__content" id="delete_alias_confirm_dialog_content">
<p>
Alias [ALIAS NAME] has been successfully deleted.
</p>
<form action="#">
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button mdl-button--raised mdl-button--colored" onClick="delete_alias_confirm_dialog.close()" id="delete_alias_confirm_dialog_ok_button">OK</button>
</div>
</form>
</div>
</dialog>
<script>
var delete_alias_confirm_dialog = document.querySelector('#delete_alias_confirm_dialog');
if (! delete_alias_confirm_dialog.showModal) {
dialogPolyfill.registerDialog(delete_alias_confirm_dialog);
}
var delete_alias_curr_name=""
function show_delete_alias_confirmation(clicked_element) {
delete_alias_curr_name=((clicked_element.parentNode).parentNode).parentNode.parentNode.querySelector('#alias_name').innerText
var delete_alias_dialog_delete_button=document.querySelector('#delete_alias_dialog_delete_button');
var delete_alias_dialog_alias_name=document.querySelector('#delete_alias_dialog_alias_name');
delete_alias_dialog_alias_name.innerHTML=delete_alias_curr_name
delete_alias_dialog.showModal();
delete_alias_dialog_delete_button.blur();
}
</script>
Check the order in which you load the CSS.
If you are loading dialog-polyfll.css before material.min.css that might be the source of the problem.
Also check if you don't have a dialog duplicate, this also results on a dialog that can't be closed on IOS.

Getting onClick to work on iPad Safari

I just inherited a website and haven't worked on website for about 15 years and am not familiar with programing for touch screens.
I have the below onClick submit code that works on all browsers (including Safari desktop on PC) that I have tested as well as using Google search on an iPad, but when attempting to press the "Submit" button when accessing the site via iPad Safari it will not fire. I've search for JQuery solutions, but am not up to speed on JQuery. Any help appreciated.
function submitentry()
{
password = document.password1.password2.value.toLowerCase()
username = document.password1.username2.value.toLowerCase()
passcode = 1
usercode = 1
for(i = 0; i
<center>
<form action="" name="password1">
<strong>User * * : </strong>
<input type="text" name="username2" size="15">
<br>
<strong>Password: </strong>
<input type="password" name="password2" size="15">
<br><br>
<input type="button" value="Submit"onClick="submitentry(); return true">
</form>
Turns out that any non-anchor element assigned a click handler in jQuery must either have an onClick attribute (can be empty like below):
onClick=""
OR
The element css needs to have the following declaration:
cursor:pointer
via : http://www.mitch-solutions.com/blog/17-ipad-jquery-live-click-events-not-working
I'm not sure but that's probably because touch devices doesn't have pointer.
Try .live():
$(document).ready(function(){
$("#submitButton").live("click", function(){
// do something
}
});
Or, try this plugin:
https://github.com/aanand/jquery.tappable.js
I suggest you to try to avoid writing unobtrusive code such inline event handlers like onclick, onmousedown, etc because different browser work differently. Especially in touch devices.
Thanks for the suggestion. Being new to jQuery it is taking me awhile to get up to speed. Below is what I got to work, so far, but still am having problems with the touch screen on iPad when accessing the site using Safari. But it does work, strangely, when I access the site using Google on the iPad. Strange, I think!
My HTML input statement is:
<input type="button" value="Submit" id="click"/>
jQuery:
$('#click') .click(function(){
submitentry();
});
I'm thinking that if I use something other than .click it might work. Just need to figure out what. We'll see...

Invoking multiple instances of the same jQuery UI dialog

I have a jQuery UI dialog with several tabs, sometimes, I need to pop up one of those tabs as a separate dialog (atop of tabbed initial dialog), so, can I achieve this by re-using the same dialog?
(of course with a bit run-time customizations, JavaScript/DOM HTML manipulations, but with the same <div></div> template initially defined and with the same HTML FORM elements IDs)
This is not the optimal solution, but could be an approach of what should you do.
HTML:
<div id="dialog" title="Basic dialog">
<div class="dtabs">
<ul>
<li>First
</li>
<li>Second
</li>
<li>Third
</li>
</ul>
<div id="tab1">
<p>First!</p>
</div>
<div id="tab2">
<p>Second!</p>
</div>
<div id="tab3">
<p>Third!</p>
</div>
</div>
</div>
<input value="Tab 1 on Dialog" type="button" alt="1" />
<input value="Tab 2 on Dialog" type="button" alt="2" />
<input value="Tab 3 on Dialog" type="button" alt="3" />
Javascript:
$(function () {
// Dialog without autoOpen just to hide it from viewport
$('#dialog').dialog({
autoOpen: false
});
$('input').click(function () {
// Clone the dialog and append it to body
// Get "tab" number to know which tab should I set as active later
var d = $('#dialog').clone().appendTo('body'),
tab = $(this).attr('alt')-1;
// Assign "dialog" behaviour and remove it when I close it
d.dialog({
autoOpen: false,
close: function (e, ui) {
$(this).dialog('destroy').remove();
}
});
// Tabs inside my dialog has "tabs" behaviour by JQueryUI
d.find('.dtabs').tabs({
active: tab
});
// Open up!
d.dialog('open');
});
});
http://jsfiddle.net/franverona/k7cuH/
Let me explain you what I did:
I create my dialog in pure HTML and using JQueryUI assign it a dialog behaviour.
Every button has a property that will tell me later what tab should I open in my future dialog.
When user click on button I clone my previous dialog, append it to body and get "tab" attribute. Then I assign it a dialog behaviour without autoOpen and with a function associated to close event to remove it from DOM (to avoid multiple dialogs on my HTML body).
Before open, I assign a tabs behaviour to all the content inside my recently created dialog (look that I'm using find function) and set as an active tab the correct tab using tab property retrieved before.
Now I'm ready to open my dialog with all set up.
I repeat: this isn't an optimal solution, but should work as a prototype of later development iterations.
Happy coding!

Dynamically rendering partial view on iPad

I'm really hoping someone can help. I just got over one big hurdle in my current project, only to hit another. I have a deadline fast approaching, so any advice would be very much appreciated.
I am developing a mobile application for iPad using MVC4 and Jquery Mobile. At a certain point in my app, the user will trigger a pop-up box, which contains "yes" and "no" buttons. If the user clicks "yes", I want to send some parameters to an action in my controller, do some database work, and then return a partial view (with updated model) that will be displayed in my main view. I have the following jquery that executes upon click of a href button that is inside a pop-up.
$(function () {
$("#popupSubmit").bind("tap", tHandler);
function tHandler(event) {
$.post('#Url.Action("LoadTestData", "WO")',
{TestKey: lblTestKey.innerHTML, TestRequestNumber: lblTestServiceRequestNum.innerHTML },
function (data) { $('#detailsDiv').html(data); $('#detailsDiv').trigger("create"); });
}
});
In the above code, #popupSubmit is the href button, LoadTestData is an Action that returns a partial view, WO is the Controller, and #detailsDiv is a placeholder div in the main view. TestKey and TestRequestNumber are parameters that must be passed to the Action. Below is the code for the Action, LoadTestData. _ShowTestPartial is the Partial View.
[HttpPost]
public ActionResult LoadTestData(string TestKey, string TestRequestNumber)
{
//do database work
return PartialView("_ShowTestPartial", model);
}
Now, all of this code works on my desktop in Safari. However, this DOES NOT work on the iPad. I've tested, and the code does make it into the tHandler event when the button is clicked on the iPad, but there's something about the URL.Action or about returning a partial view in this way that the iPad just doesn't like.
Does anyone know how to solve this issue for iPad?
Edit (additional info from comments): To be clear, the partial view isn't being rendered at all on iPad, but it is on desktop Safari (and in Chrome for that matter). I have tried replaced "create" with "pagecreate" but this actually took away the JQM styling in the desktop browers and didn't change anything about the iPad.
It also doesn't seem to matter where I place the bind function...I've tried it as a separate function. I've tried it in .ready() and in .on('pageinit'). In all of these cases, it works on desktop Safari and Chrome, but not on iPad.
Also, as I said before, the .bind("tap") works on iPad. I've tested by putting other code in the tHandler. However something in the .$post does not work on iPad.
Thank you Omar, and anyone else who has any ideas. All are welcome!
Edit # 2: On Omar's advice I moved my function to $(document).on('pageinit'). I also added error catching on the $.post. Updated code below:
$(document).on('pageinit', function () {
$("#popupSubmit").bind("tap", tHandler);
function tHandler(event) {
$.post('#Url.Action("LoadTestData", "WO")', { TestKey: lblTestKey.innerHTML, TestRequestNumber: lblTestRequestNum.innerHTML })
.done(function (data) { $('#detailsDiv').html(data); $('#detailsDiv').trigger("create"); })
.fail(function (xhr, textStatus, errorThrown) { alert(xhr.responseText); })
}
});
Fortunately, this enabled me to see the error occurring on the iPad. Unfortunately, the error coming out of $.post is "An unknown error occurred while processing your request". Everything is still running smoothly on the desktop browsers with this code.
It turns out the answer was that, on the iPad the parameters were not getting passed to $.post. lblTestRequestNum and lblTestKey are labels on my JQM popup dialog box. See below:
<div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="b" data-dismissible="false"
style="max-width:416px;" class="ui-corner-all">
<div data-role="header" data-theme="a" class="ui-corner-top">
<h1>Selection <label id="lblTestRequestNum" style="text-align:left; height:22px; font-size:14px;">#Model.TestRequestNumber</label></h1>
</div>
<div data-role="content" data-theme="a" class="ui-corner-bottom ui-content">
<h3 class="ui-title" style="text-align:center; height:22px;">Are you sure?</h3>
<label id="lblTestKeyLabel" style="text-align:left; height:22px; font-size:14px; margin-left:95px;">Test Key: </label>
<label id="lblTestKey" style="text-align:left; height:22px; font-size:14px;"></label>
<label id="lblTestType" style="text-align:left; height:22px; font-size:14px; margin-left:95px;"></label>
<a id="popupSubmit" data-role="button" data-inline="true" data-rel="back"
data-mini="true" data-theme="b" style="width:150px;" type="submit">Yes</a>
<a href="#" data-role="button" data-inline="true" data-rel="back"
data-mini="true" data-transition="flow" data-theme="b" style="width:150px;">No</a>
</div>
</div>
On the desktop, Safari was able to retrieve the parameters I needed from the labels in the popup. But on iPad, it could not. So, I simply found places outside of the pop-up, in my main view to display/retrieve my parameters from. Lesson learned: Don't expect iPad to be able to read anything from labels/inputs inside your pop-up dialog.

Resources