Code Monkey home page Code Monkey logo

nova-phone-number's Introduction

Laravel Nova Phone Number Field

Latest Version on Packagist License Total Downloads

A Laravel Nova field to format using a dynamic input mask and additional phone number validation.

NOTE: This field utilizes Propaganistas / Laravel-Phone package for validation.

Image 1

Installation

To install this tool, use the installation code below:

composer require dniccum/phone-number

Code

To use the field, add the following code to your Nova resource. As this is a field, all of the default field properties can be applied.

use Dniccum\PhoneNumber\PhoneNumber;

PhoneNumber::make('Phone Number')

Options

To support multiple types and formats of phone numbers, this field has multiple methods for input masking and validation that are available.

Defaults

Method/Options Default
format string: '(###) ###-####'
placeholder string: '[Name of Field]'
useMaskPlaceholder boolean: false
country string: 'US'
countries string[]: ['US']
disableValidation boolean: false
linkOnIndex boolean: false
linkOnDetail boolean: false

format

PhoneNumber::make('Phone Number')
    ->format('###-###-####')

Type: string

Default: (###) ###-####

This is the value that the javascript controlling the input mask will use define it's values; and depending the field's configuration the placeholder text. To indicate numbers, use the hash (#) symbol.

Note: Other types of content can be included within this input like an phone extension:

PhoneNumber::make('Phone Number')
    ->format('###-###-#### ext ####')

However the built-in phone number validation will FAIL as this is technically an invalid phone number. To prevent the validation from failing, turn off the phone number validation like so:

PhoneNumber::make('Phone Number')
    ->format('###-###-####')
    ->disableValidation()

placeholder

PhoneNumber::make('Phone Number')
    ->placeholder('Personal Home Number')

Type: string

Default: [Name of the Field]

If you would like to override the default placeholder supplied by Nova, which is the name of field, user a simple string.

Note: If you are telling the input to override the placeholder by using the input's mask with the useMaskPlaceholder method, this will not work.

useMaskPlaceholder

PhoneNumber::make('Phone Number')
    ->useMaskPlaceholder()

Type: boolean

Default: false

This will tell the field to replace the input's defined placeholder with the input mask from the ->format() method.

country

PhoneNumber::make('Phone Number')
    ->country('CA')

Type: string

Default: US

This tells the field what type of phone number validation to use. To define a type of validation, define a ISO 3166-1 alpha-2 compliant country code.

You can only define one country here. If you would like to define more than one, please see the ->countries() method.

NOTE: This field utilizes Propaganistas / Laravel-Phone package for validation.

countries

PhoneNumber::make('Phone Number')
    ->countries(['US', 'CA'])

Type: string[]

Default: US

If you would like to define more than one country to validate against, define string-based array of ISO 3166-1 alpha-2 compliant country codes.

NOTE: This field utilizes Propaganistas / Laravel-Phone package for validation.

linkOnIndex

PhoneNumber::make('Phone Number')
    ->linkOnIndex()

Type: boolean

Default: false

Render's the phone number as a clickable link on the index view.

linkOnDetail

PhoneNumber::make('Phone Number')
    ->linkOnDetail()

Type: boolean

Default: false

Render's the phone number as a clickable link on the detail view.

Credits

License

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

nova-phone-number's People

Contributors

batformat avatar bradenkeith avatar dependabot[bot] avatar dniccum avatar lintaba avatar shawnheide avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.