1

I have an angular ionic cordova app where I'm trying to trigger the click of an input from another span (so that I can trigger the native datetime keyboard in cordova) . However the click event doesn't seem to be triggered on the input field. Looking at the debugger, the click function of the document element is not null, but doesn't seem to do anything when triggered from the span. This works on a normal jsfiddle as commenters have noted, but when in an ionic environment, it doesn't - see this codepen

http://codepen.io/MonkeyBonkey/pen/OPmOrZ

<span onclick="document.getElementById('whenPickerInput').click();">
  {{(when | amCalendar)}}
</span>

<input 
  onclick="alert('input clicked')" 
  id="whenPickerInput" 
  type="datetime-local" 
  ng-model="when" />
7
  • 1
    Works here: jsfiddle.net/hapehpcn Commented Jan 20, 2015 at 14:26
  • @tymeJV I tested too and works. Commented Jan 20, 2015 at 14:27
  • hmm must be something with the ionic enviroment, I'll try to set up a codepen or jsfiddle with the ionic libs loaded Commented Jan 20, 2015 at 14:33
  • try on this codepen codepen.io/MonkeyBonkey/pen/OPmOrZ Commented Jan 20, 2015 at 14:37
  • 1
    @PSL the datepicker opens automatically on mobile devices because the input type is datetime-local. Figured out that ionic has a tap system that is interfering, answer below Commented Jan 20, 2015 at 15:26

2 Answers 2

3

so it looks like ionic has it's own click handler that removes the 300ms delay in mobile. I have to remove that tap system for the input so that I can trigger the click event

http://ionicframework.com/docs/api/page/tap/

<input data-tap-disabled="true" />
Sign up to request clarification or add additional context in comments.

Comments

0

You found a solution with <input data-tap-disabled="true" /> But better will be to change your code and don't use onclick. In Angular/Ionic u can use ng-click.

1 Comment

sure, ng-click or onclick will both work - and ng-click is what I used in my final solution. I wanted to use onclick in the example to better isolate the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.