Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfkaya committed Aug 10, 2024
1 parent de73eb2 commit a355d57
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/js/filament-phone-input.js

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions resources/js/filament-phone-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,19 @@ export default function phoneInputFormComponent({
this.$nextTick(() => {
this.formatState();
});

this.updateCountryState();
}
},

formatState() {
const displayNumberFormat =
this.options.displayNumberFormat || "E164";
const displayNumberFormat = this.options.displayNumberFormat || "E164";
const numberFormat = this.options.inputNumberFormat || "E164";

this.state =
this.intlTelInput.getNumber(
intlTelInput.utils.numberFormat[numberFormat]
) || null;
this.state = this.intlTelInput.getNumber(intlTelInput.utils.numberFormat[numberFormat]) || null;

if (this.options.formatAsYouType !== true) {
this.input.value =
this.intlTelInput.getNumber(
intlTelInput.utils.numberFormat[displayNumberFormat]
) || null;
this.input.value = this.intlTelInput.getNumber(intlTelInput.utils.numberFormat[displayNumberFormat]) || null;
}
},

Expand All @@ -169,6 +164,8 @@ export default function phoneInputFormComponent({
const countryData = this.intlTelInput.getSelectedCountryData();

this.countryState = countryData.iso2?.toUpperCase();

window.duskCountryValue = this.countryState;
},

commitState() {
Expand Down
4 changes: 2 additions & 2 deletions resources/views/phone-input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
dusk="phone-input.{{ $id }}"
class="inline-flex w-full"
>
<span
<div
class="w-full"
x-ignore
@if (FilamentView::hasSpaMode())
Expand Down Expand Up @@ -132,7 +132,7 @@ class="w-full"
], escape: false)
"
/>
</span>
</div>
</div>
</x-filament::input.wrapper>
</x-dynamic-component>
Expand Down
34 changes: 34 additions & 0 deletions tests/Browser/PhoneInputCountryStateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Ysfkaya\FilamentPhoneInput\Tests\Browser;

use Laravel\Dusk\Browser;
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
use Ysfkaya\FilamentPhoneInput\Tests\BrowserTestCase;
use Ysfkaya\FilamentPhoneInput\Tests\Fixtures\FilamentPhoneInputUserResource;

class PhoneInputCountryStateTest extends BrowserTestCase
{
protected ?string $resource = PhoneInputCountryStateResource::class;

/** @test */
public function it_can_state_phone_country()
{
$this->phoneTest(
fn (Browser $browser) => $browser
->waitFor('@phone-input.data.phone')
->pause(300)
->typeSlowly('@phone-input.data.phone input.fi-input', '5301111111')
->pause(300)
->assertScript('window.duskCountryValue', 'TR')
);
}
}

class PhoneInputCountryStateResource extends FilamentPhoneInputUserResource
{
public static function getPhoneInput(): ?PhoneInput
{
return parent::getPhoneInput()->countryStatePath('phone_country');
}
}
33 changes: 33 additions & 0 deletions tests/Browser/PhoneInputStrictModeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Ysfkaya\FilamentPhoneInput\Tests\Browser;

use Laravel\Dusk\Browser;
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
use Ysfkaya\FilamentPhoneInput\Tests\BrowserTestCase;
use Ysfkaya\FilamentPhoneInput\Tests\Fixtures\FilamentPhoneInputUserResource;

class PhoneInputStrictModeTest extends BrowserTestCase
{
protected ?string $resource = PhoneInputStrictModeResource::class;

/** @test */
public function it_should_be_not_allow_string()
{
$this->phoneTest(
fn (Browser $browser) => $browser
->waitFor('@phone-input.data.phone')
->typeSlowly('@phone-input.data.phone input.fi-input', 'not allow string 5301111111')
->pause(300)
->assertValue('@phone-input.data.phone input.fi-input', '0530 111 11 11')
);
}
}

class PhoneInputStrictModeResource extends FilamentPhoneInputUserResource
{
public static function getPhoneInput(): ?PhoneInput
{
return parent::getPhoneInput()->strictMode();
}
}

0 comments on commit a355d57

Please sign in to comment.