Skip to content

Commit

Permalink
Added "disableMobile" (#18)
Browse files Browse the repository at this point in the history
* Added disableMobile Option

Added "disableMobile" built into Flatpickr defaulting to "true".

When flatpickr detects a mobile browser, it turns the date input into a native date/time/datetime input.

This limits Flatpickr features and styling for just mobile and can cause compatibility issues.

* Update Flatpickr.php
  • Loading branch information
CThomas87 committed May 30, 2023
1 parent b93c1b7 commit 5a02037
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Components/Flatpickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
public bool $showWeekNumbers = false,
public bool $time24hr = true,
public bool $clearable = false,
public bool $disableMobile = true,
) {
$this->id = $this->id ?: Str::random(16);

Expand Down Expand Up @@ -61,6 +62,7 @@ public function config(): array
'weekNumbers' => $this->showWeekNumbers ?: null,
'wrap' => $this->clearable ?: null,
'showMonths' => $this->visibleMonths,
'disableMobile' => $this->disableMobile ?: false,
])
->merge($this->firstDayOfWeekConfig())
->merge($this->config)
Expand Down Expand Up @@ -104,7 +106,7 @@ private function mode()

private function value(): string|int|array|null
{
if (! $this->value) {
if (!$this->value) {
return null;
}

Expand Down Expand Up @@ -157,7 +159,7 @@ private function firstDayOfWeekConfig()

private function time24hr(): ?bool
{
if (! $this->showTime) {
if (!$this->showTime) {
return null;
}

Expand All @@ -176,13 +178,13 @@ public function defaultClearer()

private function throwValueExceptions()
{
if (! $this->value) {
if (!$this->value) {
return;
}

switch ($this->mode()) {
case 'multiple':
if (! is_array($this->value)) {
if (!is_array($this->value)) {
throw new \Exception("The value must be array of dates or Carbon instances when multiple is set.");
}

Expand All @@ -197,11 +199,11 @@ private function throwValueExceptions()
return;
}

if (! is_string($this->value)) {
if (!is_string($this->value)) {
throw new \Exception("The value must be string when range is set.");
}

if (! Str::contains($this->value, ' to ')) {
if (!Str::contains($this->value, ' to ')) {
throw new \Exception("The two dates must be string and separated by ' to ' in between.");
}

Expand Down

0 comments on commit 5a02037

Please sign in to comment.