A phone input component that uses intl-tel-input for Laravel Filament

Overview

Filament Phone Input

Filament Phone Input

This package provides a phone input component for Laravel Filament. It uses International Telephone Input to provide a dropdown of countries and flags.

Installation

You can install the package via composer:

composer require ysfkaya/filament-phone-input

Usage

use Filament\Forms;
use Ysfkaya\FilamentPhoneInput\PhoneInput;

  //...
  public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->required(),

                Forms\Components\TextInput::make('email')
                    ->required()
                    ->email()
                    ->unique(ignoreRecord: true),

                PhoneInput::make('phone'),
            ]);
    }

You may set the display format of the phone number by passing a format string to the displayNumberFormat method. The default format is NATIONAL. That means the phone number will be displayed in the format of the selected country.

Available formats are;

  • PhoneInputNumberFormat::E164
  • PhoneInputNumberFormat::INTERNATIONAL
  • PhoneInputNumberFormat::NATIONAL
  • PhoneInputNumberFormat::RFC3966
use Ysfkaya\FilamentPhoneInput\PhoneInputNumberType;

PhoneInput::make('phone')
    ->displayNumberFormat(PhoneInputNumberFormat::E164),

Filament Phone Input

You may set the input value type by passing a type string to the inputNumberFormat method. The default type is E164. That means the phone number will be saved in the format of the selected country to the database.

use Ysfkaya\FilamentPhoneInput\PhoneInputNumberType;

PhoneInput::make('phone')
    ->inputNumberFormat(PhoneInputNumberType::NATIONAL),

You may set the focus input type by passing a type string to the focusInputType method. The default value is false.

use Ysfkaya\FilamentPhoneInput\PhoneInputFocusInputType;

PhoneInput::make('phone')
    ->focusInputType(PhoneInputFocusInputType::E164),

Filament Phone Input

You may disable the dropdown by using the disallowDropdown method:

PhoneInput::make('phone')
    ->disallowDropdown(),

Filament Phone Input

You may set the auto placeholder type by using the autoPlaceholder method:

PhoneInput::make('phone')
    ->autoPlaceholder('polite'), // default is 'aggressive'

You may set the additional classes to add to the parent div by using the customContainer method:

PhoneInput::make('phone')
    ->customContainer('w-full'),

You may set the custom placeholder by using the customPlaceholder method:

PhoneInput::make('phone')
    ->customPlaceholder('jsMethodName'),

And you should add a js method to your blade file like this:

window.jsMethodName = function(selectedCountryPlaceholder, selectedCountryData) {
    return 'Custom Placeholder';
}

You may set the exclude countries by using the excludeCountries method:

PhoneInput::make('phone')
    ->excludeCountries(['us', 'gb']),

You may set the initial country by using the initialCountry method:

PhoneInput::make('phone')
    ->initialCountry('us'),

You may set the only countries by using the onlyCountries method:

PhoneInput::make('phone')
    ->onlyCountries(['tr','us', 'gb']),

Filament Phone Input

You may set the format on display by using the formatOnDisplay method:

PhoneInput::make('phone')
    ->formatOnDisplay(false),

You may set the geoIp lookup by using the geoIpLookup method:

PhoneInput::make('phone')
    ->geoIpLookup('jsMethodName'),

And you should add a js method to your blade file like this:

window.jsMethodName = function(callback) {
    $.get('http://ipinfo.io', function() {}, "jsonp").always(function(resp) {
        var countryCode = (resp && resp.country) ? resp.country : "";
        callback(countryCode);
    });
}

You may set the placeholder number type by using the placeholderNumberType method:

PhoneInput::make('phone')
    ->placeholderNumberType('FIXED_LINE'),

You may set the preferred countries by using the preferredCountries method:

PhoneInput::make('phone')
    ->preferredCountries(['tr','us', 'gb']),

You may set the separate dial code by using the separateDialCode method:

PhoneInput::make('phone')
    ->separateDialCode(true),

You can find the more documentation for the package here

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...

Convert table to card when on phone

Convert table to card when on phone

Convert table to card see index.html for example converts table to card when viewport is = 425px HTML Syntax table !-- table headings -- th

May 3, 2022

A Tempermonky / Greasemonkey plugin which can help you export your class schedule to the calendar on your phone / pad / PC / Mac.

A Tempermonky / Greasemonkey plugin which can help you export your class schedule to the calendar on your phone / pad / PC / Mac.

WHU Class Schedule Export as iCS Languages: English | 簡體中文 | 繁體中文 Changelog v0.90.1 - Sep 18, 2022 Fix bugs: Fix an error when a class have multiple s

Sep 7, 2022

Instruction how to install laravel echo and pusher without vuejs or even npm

This 2 .js files are used to listen from server broadcasting with laravel-websockets, so that you don't need the use of Vue.js in your laravel app Fol

Sep 28, 2022

esbuild plugin to generate mix-manifest.json file compatible with Laravel Mix.

esbuild-mix-manifest-plugin An esbuild plugin to generate a mix-manifest.json compatible with Laravel Mix. Installation You can install the plugin via

Dec 25, 2022

Package for creating entity framework in a nodejs project based on Laravel artisan system.

Artisan Structuring system for an ExpressJs project. Version [Production] release 0.2.0 artisan - npm package Dependencies nodejs Installations Instal

Dec 11, 2022

Arquivos do Curso de Laravel 9.x

Setup Docker Para Projetos Laravel 9 com PHP 8 Assine a Academy, e Seja VIP! Passo a passo Clone Repositório git clone https://github.com/especializat

Dec 6, 2022

A demo app showingcasing laravel-livewire-wizard

A demo app showingcasing laravel-livewire-wizard

A demo of spatie/laravel-livewire-wizard This repo contains a Laravel app to showcase the spatie/laravel-livewizard package. Usage Clone the repo Copy

Dec 29, 2022

E-commerce website using Laravel, Tailwindcss and Alpine.js

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Dec 12, 2022

🍺 Integrates Laravel Pint into your VSCode projects for automatic code formatting

Laravel Pint for VS Code This extension is NOT official from the Laravel team. Take a look into the official project. Integrates Laravel Pint into you

Dec 8, 2022
Comments
  • Support both lazy and debounce + @svg

    Support both lazy and debounce + @svg

    Please support for both lazy and debounced field types. Also use @svg() instead of dynamic component for everyone who chose to disable blade-icons components. The last is a non-breaking change. (Filament v3 will change to using the same code style)

    opened by tanthammar 1
  • Dynamically setting phone input does not make value visible

    Dynamically setting phone input does not make value visible

    Hi,

    When I set dynamically set the value of the phone field like so:

    Field::make('example')->afterStateUpdated(function (Closure $set) {
        $set('phone', '+31612345678');
    }),
    

    the field won't display the value (but it IS being saved to the field because the new value is there when saving the form). It doesn't matter in which format I use for the phone number, it won't display it.

    Edit: it looks like the phoneInputFormComponent Alpine function needs a watcher on the state.

    good first issue 
    opened by arjendejong12 0
Releases(v1.2.0)
Owner
Yusuf Kaya
Full Stack Web Developer
Yusuf Kaya
front.phone is a Javascript library that identifies, validates and formats phone numbers.

front.phone front.phone is a Javascript library that identifies, validates and formats phone numbers. Demo The main goal of this project is to create

VTEX 55 Oct 27, 2022
🌐 Text Input Component for validating and formatting international phone numbers.

React Native Intl Phone Field Try the Expo Snack ?? ??️ Demo It's a javascript-only (no native code) component that can run in iOS, Android, Expo & Re

Ivanka Todorova 24 Jul 8, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A Drop-in Jalali Replacement for filament DateTimePicker

Filament Jalali Date Time Picker Field This package is a Drop-in replacement for DatePicker and DateTimePicker field type you just need to replace tho

AriaieBOY 8 Dec 3, 2022
Easy way to change filament theme color on the fly.

Filament Theme Color Easy way to change filament theme color on the fly. In some projects, it is interesting to be able to change the main colors of a

Uccello Labs 8 Nov 20, 2022
A very simple tool that generates multiple spellings of a phone number (to effectively search for it using the OR operator and quotes)

phonenumberqueryconstructor A very simple tool that generates multiple writings of a phone number (to effectively search for it using the OR operator

Cyb_detective 10 Dec 7, 2022
Verify your E-Mail and Phone Number using link sent over mail and sms.

Phone-and-Mail-Verification-With-Link Verify your E-Mail and Phone Number using link sent over mail and sms. Endpoints POST /user/create Body { "n

Prasoon Soni 5 Sep 14, 2022
Verify your E-Mail and Phone Number using link sent over mail and sms.

Send Verification Link ✅ Explore the docs » • Report Bug • Request Feature • About The Project Verify your E-Mail and Phone Number using link sent ove

Prasoon Soni 4 Jun 28, 2022