Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker: disable input on mobile #4592

Open
wants to merge 4 commits into
base: rel-1.2
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Source/Blazorise/wwwroot/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function initialize(element, elementId, options) {
const defaultOptions = {
enableTime: options.inputMode === 1,
dateFormat: options.inputMode === 1 ? 'Y-m-d H:i' : 'Y-m-d',
allowInput: !(options.disableMobile || false),
altInput: !(options.disableMobile || false),
allowInput: !(isMobile() && (options.disableMobile || false)),
altInput: !(isMobile() && (options.disableMobile || false)),
Comment on lines +42 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mind can't think today :D Is this right? Does it handle every case?
Might be a better read if you just bring the isMobile() out.
I.E
!IsMobile() || (isMobile() && !options.disableMobile)

But I think it's those pipes that are killing me, again is it a coalesce operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is actually broken on flatpickr side. They don't detect the mobile device properly. So I was trying to come up with a workaround, even pushed a PR on their repo, but it still seems not to detect all of the mobile devices.

altFormat: options.displayFormat ? options.displayFormat : (options.inputMode === 1 ? 'Y-m-d H:i' : 'Y-m-d'),
defaultDate: options.defaultDate,
minDate: options.min,
Expand Down Expand Up @@ -218,4 +218,10 @@ export function select(element, elementId, focus) {
if (picker && picker.altInput) {
utilities.select(picker.altInput, null, focus);
}
}

function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
}