Git Product home page Git Product logo

ion-digit-keyboard-v2's Introduction

Ionic 2 Digit Keyboard banner

Ionic 2 Digit Keyboard

Try it now using Ionic View with the following id: c53c6c00.

1 - Info

Version: 2.0
Author: Skol (Vincent Letellier)
Email: [email protected]
Donations: You're really welcome to donate, any amount at any time :-)

2 - Changelog

  • What's coming next (ASAP) ?
    • A global service to manage keyboards and dependant component(s).
    • Custom text input component:
      • Prevent native keyboard to show up.
      • Auto showing keyboard on focus.
      • Auto scroll to the input and scroll freeze.
  • Juin 1, 2017
    • Updated demo to the latest Angular & Ionic versions (not affecting Ionic v2).
    • Refactored the component, now module oriented (see updated tutorial).
    • Can now be used on multiple pages without issues.
    • Be careful, IonDigitKeyboard componnet has been renamed to IonDigitKeyboardCmp.
  • April 8, 2017
    • Added text property on action buttons. This allows having a decimal button for-example.
    • Updated README with text property and example (see 4.3 Options).

3 - Installation & loading

Copy the ion-digit-keyboard module folder into your project (under src/components/ for example). Import the module in your app.module.ts.

// app.module.ts
import { IonDigitKeyboard } from '../components/ion-digit-keyboard/ion-digit-keyboard.module';
// ...
@NgModule({
    declarations: [
        MyApp,
        // ...
    ],
    imports: [
        IonDigitKeyboard,
        IonicModule.forRoot(MyApp)
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp,
        // ...
    ],
    providers: []
})
export class AppModule { }

4 - Usage

4.1 - Importing in component

You can import the keyboard wherever you want, globally in app.component.ts or on every page. For a global usage, you can insert it under ion-nav for example.

// app.component.ts
import { IonDigitKeyboardCmp } from '../components/ion-digit-keyboard';
<!-- app.html (or inline template under app.component.ts) -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>

<ion-digit-keyboard></ion-digit-keyboard>

Don't forget to import ion-digit-keyboard.scss in app.scss.

@import './components/ion-digit-keyboard/ion-digit-keyboard';

With this minimalist configuration, you can already use the keyboard, just add the buttonClick event !

<ion-digit-keyboard (buttonClick)="onKeyboardButtonClick()"></ion-digit-keyboard>
onKeyboardButtonClick(key: number) {
    // Log the pressed key
    console.log(key);
}

You could also use the onClick subscriber, to do so, you'll need to use @ViewChild() to access the keyboard component, and ngOnInit to unsure it is instantiated:

@ViewChild(IonDigitKeyboardCmp) keyboard;

//...

ngOnInit(): void {
    this.keyboard.onClick.subscribe((key) => {
        console.log('From subscriber: ', key);
    });
}

CAUTION - In case no event is fired, be sure your browser Mobile Emulation is turned ON, since the keyboard is using the touchend event.

4.2 - Public methods & events

Here are the public component methods (this.keyboard.show(myCallback)):

  • show (function): Show the keyboard. The optional callback will be called after transition ends.
  • hide (function): Hide the keyboard. The optional callback will be called after transition ends.
  • destroy (function): Destroy the keyboard component and call the optional callback.

And here are the available events ((buttonClick)="btnClickFunction($event)"):

  • buttonClick: Any button clicked
  • leftActionClick: Left action clicked
  • rightActionClick: Right action clicked
  • numberClick: Number key clicked

Example using buttonClick:

<ion-digit-keyboard (buttonClick)="onKeyboardButtonClick()"></ion-digit-keyboard>
// app.component.ts
public onKeyboardButtonClick(key: any) {
    // Key can be a number (0-9) or a string ('left' or 'right')
}

There is also 3 available subscribers:

  • onClick: Same as buttonClick event.
  • onShow: Use this method to register a callback when the keyboard is showing up (after the animation)
  • onHide: Use this method to register a callback when the keyboard is getting hidden (also after the animation)
this.keyboard.onClick.subscribe((key: any) => {
    // Do something
});
this.keyboard.onShow.subscribe(() => {
    // Do something
});

4.3 - Options

First, I recommend you to import the IonDigitKeyboardOptions interface.

// app.component.ts
import { IonDigitKeyboardCmp, IonDigitKeyboardOptions } from '../components/ion-digit-keyboard';

Keyboard options (IonDigitKeyboardOptions interface):

  • align (string): Keyboard horizontal alignement (no effects on full width). Can be 'left', 'center' or 'right'.
  • width (any): Keyboard width, can be expressed as number or as string for percents and pixels.
  • visible (boolean): Keyboard visibility.
  • leftActionOptions (ActionOptions): Keyboard left action options.
  • rightActionOptions (ActionOptions): Keyboard right action options.
  • roundButtons (boolean): If set to true, it turns the buttons to rounded buttons. It won't looks good for most of the themes.
  • showLetters (boolean): If set to true, it will display letters under buttons number.
  • swipeToHide (boolean): If set to true, swiping the keyboard from top to bottom will hide it.
  • theme (string): Keyboard visual theme. Available themes: 'light', 'dark', 'ionic', 'opaque-black', 'opaque-white', 'dusk', 'nepal', 'alihossein', 'messenger'. Also accessible from IonDigitKeyboardCmp.themes. You can put all of them on the ion-digit-keyboard component:
<ion-digit-keyboard
    [align]="keyboardSettings.align"
    [width]="keyboardSettings.width"
    [visible]="keyboardSettings.visible"
    [leftActionOptions]="keyboardSettings.leftActionOptions"
    [rightActionOptions]="keyboardSettings.rightActionOptions"
    [roundButtons]="keyboardSettings.roundButtons"
    [showLetters]="keyboardSettings.showLetters"
    [swipeToHide]="keyboardSettings.swipeToHide"
    [theme]="keyboardSettings.theme"
    (numberClick)="numberClick($event)"
>
</ion-digit-keyboard>
keyboardSettings: IonDigitKeyboardOptions = {
    align: 'center',
    //width: '85%',
    visible: false,
    leftActionOptions: {
        iconName: 'ios-backspace-outline',
        fontSize: '1.4em'
    },
    rightActionOptions: {
        //iconName: 'ios-checkmark-circle-outline',
        text: '.',
        fontSize: '1.3em'
    },
    roundButtons: false,
    showLetters: true,
    swipeToHide: true,
    theme: 'ionic'
}

Action options (ActionOptions interface):

  • hidden (boolean): Display the action button or not.
  • fontSize (string): Optional font size adjustement.
  • iconName (string): The action Ionic icon name to display.
  • text (string): A text to display on the action.

As you probably already understood, none of those otpions are required ! Also, setting both iconName and text properties will only display the icon.

5 - Toolbar

You can add an ion-toolbar inside the ion-digit-keyboard component:

<ion-digit-keyboard>
    <ion-toolbar no-border-bottom>
        <ion-buttons start>
            <button ion-button (click)="hideKeyboard()">Cancel</button>
        </ion-buttons>
        <ion-buttons end>
            <button ion-button solid>Next</button>
            <button ion-button solid>Done</button>
        </ion-buttons>
    </ion-toolbar>
</ion-digit-keyboard>

6 - Example / demo

Simply clone this repo, run npm install and ionic serve.

ion-digit-keyboard-v2's People

Contributors

eddul-h avatar skol-pro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ion-digit-keyboard-v2's Issues

Change keyboard design

is it possible to change the keyboard buttons design background to a custom one?
please let me know i have a photo for each number how can i append the current CSS

How to unsubscribe and use clear() method ?

Hi, i need to know how to unsubscribe and clear() all events when
IonDigitKeyboard.hide();
because i using this keyboard on more than one page, which now when leave from one page and keyboard is show on another page, the last events example [ leftActionClick, rightActionClick ] still come from first page

// @TODO unsubscribe and use clear() method

thanks for your time
regards

.digit-keyboard-key { margin: 1px !important }

Hello friend, I noticed the "margin: 1px !important" of the .digit-keyboard-key class is overriding the "margin: 0 auto" when setting roundButtons to true, causing the number keys to not be centered. Thanks for the great little digit keyboard!
screen shot 2017-02-17 at 3 50 36 pm

Icons are not displayed

Hello !

I develop an Ionic v3 application and I use your component (Thanks a lot for it :D).

HTML view

<ion-header>
    <ion-navbar hideBackButton>
        <ion-title>Connexion</ion-title>
    </ion-navbar>
</ion-header>


<ion-content padding>
    <div id="login-ico" text-center [class.hide]="isKeyboardVisible">
        <img src="assets/img/logo.png"/>
    </div>
    <form [formGroup]="pinFormGroup">
        <pin formControlName="pin" [keyboard]="keyboard" [content]="content"></pin>
        <div text-center padding-vertical [class.hide]="isKeyboardVisible">
            <span (click)="gotoForget()">J'ai oublié mon code</span>
        </div>
        <div text-center class="fix-bottom" [class.hide]="isKeyboardVisible">
            <button ion-button round large extend color="oscar-pink" (click)="validPin()" [disabled]="!pinFormGroup.valid">Valider</button>
        </div>
    </form>
</ion-content>

<ion-digit-keyboard
        [align]="keyboardSettings.align"
        [width]="keyboardSettings.width"
        [visible]="keyboardSettings.visible"
        [rightActionOptions]="keyboardSettings.rightActionOptions"
        [leftActionOptions]="keyboardSettings.leftActionOptions"
        [roundButtons]="keyboardSettings.roundButtons"
        [showLetters]="keyboardSettings.showLetters"
        [swipeToHide]="keyboardSettings.swipeToHide"
        [theme]="keyboardSettings.theme"
></ion-digit-keyboard>

TS file

import {Component, ViewChild} from '@angular/core';
import {Content, IonicPage, Keyboard, MenuController, NavController} from 'ionic-angular';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {Bridge} from "../../../providers/bridge";
import {IonDigitKeyboardOptions} from "../../../components/ion-digit-keyboard/interfaces/ion-digit-keyboard.interface";
import {IonDigitKeyboardCmp} from "../../../components/ion-digit-keyboard/components/ion-digit-keyboard-cmp/ion-digit-keyboard-cmp";
import {LoaderProvider} from "../../../providers/loader";

@IonicPage()
@Component({
    selector: 'page-pin',
    templateUrl: 'pin.html',
})
export class PinPage {
    @ViewChild(IonDigitKeyboardCmp) keyboard;
    @ViewChild(Content) content;

    private pinFormGroup: FormGroup;
    public isKeyboardVisible: boolean = false;

    public keyboardSettings: IonDigitKeyboardOptions = {
        align: 'center',
        visible: false,
        rightActionOptions: {
            hidden: false,
            iconName: 'ios-checkmark-circle-outline',
            fontSize: '1.4em'
        },
        leftActionOptions: {
            hidden: false,
            iconName: 'ios-backspace-outline',
            fontSize: '1.4em'
        },
        roundButtons: false,
        showLetters: true,
        swipeToHide: true,
        theme: 'light'
    };

    constructor(public navCtrl: NavController,
                private _formBuilder: FormBuilder,
                private _bridge: Bridge,
                private _menuCtrl: MenuController,
                private _nativeKeyboard: Keyboard,
                private _loaderProdider: LoaderProvider) {

        this._menuCtrl.enable(false);

        this.pinFormGroup = this._formBuilder.group({
            pin: ['', Validators.compose([Validators.required, Validators.pattern('[0-9]{4}')])]
        });
    }

    ionViewDidLoad() {
        this.keyboard.onShow.subscribe(() => {
            this._nativeKeyboard.close();
            this.isKeyboardVisible = true;
        });

        this.keyboard.onHide.subscribe(() => {
            this.isKeyboardVisible = false;
        });
    }

    public gotoForget() {
        this.navCtrl.push('ForgetPinPage');
    }

    public validPin() {
        if (this.pinFormGroup.valid) {
            this._loaderProdider.present();
            this._bridge.checkPin(this.pinFormGroup.value.pin)
                .subscribe(() => {
                    this._loaderProdider.dismiss();
                    this._menuCtrl.enable(true);
                    this.navCtrl.push('IndexPage');
                });
        }
    }
}

But with this config no one icon are displayed :( What's the problem ?

thanks.

Key events not working

Hi, thanks for the beautiful keyboard.

I got one issue the events don't work for me. I cloned your project and tested it there. It doesn't log the key inputs.

for example this function

numberClick(key: number) {
console.log('From event: ', key);
}

Am i missing something? I followed the docs from top to bottom.

Thanks in advance!

Landscape-Mode Size

Is there a way to control the height of the keyboard in landscape-mode?
It takes up nearly the whole Screen and there is no space for showing the Input.

Bottom buttons

Hi Skol-pro, congratulations its so cool the keyboard, but nevertheless I don´t know what to do for show the button left and right, just apear the buttons with numbers.

I'd be grateful with your support.

Error NO_ERRORS_SCHEMA

  1. If 'ion-digit-keyboard' is an Angular component and it has 'roundButtons' input, then verify that it is part of this module.
  2. If 'ion-digit-keyboard' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
  3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("ns]="keyboardSettings.leftActionOptions"

How to switch between numbers keypad to alphabets keypad

hi

How to switch between numbers keypad to alphabets keypad, its working for numbers but how to switch between from this numbers to alphabets what are displaying on keyboard. I need how to set the settings for this, please help me i need in Angular 5 please do need full
Screenshot_20190613_112801

Cannot find module '@ionic/app-scripts'

C:\ion-digit-keyboard-v2 (master)
λ ionic serve
? Looks like this is an Ionic Angular project, would you like to install @ionic/cli-plugin-io
nic-angular and continue? Yes

npm install --save-dev --save-exact @ionic/cli-plugin-ionic-angular@latest
√ Running command - done!
Error: Cannot find module '@ionic/app-scripts'

C:\ion-digit-keyboard-v2 (master)
λ ionic serve
Error: Cannot find module '@ionic/app-scripts'

confirm button in toolbar can't stopPropagation

cancle Next confirm

code in ts file:
hideKeyboard(event?) {
console.log(event)
event.stopPropagation();
event.preventDefault();
IonDigitKeyboard.hide();
}

when i click the the confirm button the keyboard hide succesfully
but it cause the event in content behind the keyboard

toolbar above the togglebutton ,everytime i colse the keyboard
the toggle button event was called

can you help me resolve the problem ?
ths

Doesn't Work

Followed your instructions in the Read Me file.

Does not work as advertised.

Key board cannot show or hide.

Left- and RightButton Icon doesn't show up

By setting up an icon by iconName in IonDigitKeyboardOptions it will not be displayed in the App.
The specific code in the components html is in comments..
Uncommenting this leads to an error on building the app.

Using keyboard with list of inputs

Greetings...

I have a scrolling list of ion-inputs.. when I call up your keyboard it covers some of the inputs. Any suggestions on how to use it with a list of inputs. I can seem to figure out how to shrink the scrolling area so I can see the last inputs in the list.

Thank you in advance for your time..
Cheers.. Mark..

Feature Request (Keyboard Support For Web)

Hey I came across a use case for HostListener that would be an awesome addition to this project.

Not sure if it already exists somewhere and i missed it though. but here's the following code i'm using.

`import {HostListener} from '@angular/core';`
`
export class MyClass{
    @HostListener('window:keyup', ['$event'])
     onKeyup(event: any) {
           if(event.key === 'Backspace'){
                this.onKeyboardButtonClick('left');
           }
           if(Number(event.key) >= 0 && Number(event.key) <=9){
                this.onKeyboardButtonClick(event.key);
           }
     }
}
`

how to input alphabets also

Hi,

I used this component its awesome working perfectly for numbers but coming for alphabets under the number keys how to trigger for alphabets. Hence please kindly help me.

regards,
chaitanya

Ionic 3 - can't import globally to app.module.ts

Hi,

I want to tell that this plugin is great!

I just started having a problem after using it on multiple pages.

I am using subscribe method to get pressed keys and when I import it to more than one page (lazy loaded), it's emitting more than one press.

The problem will probably be that I was declaring it for each page separately.

How should I import it to have it globally and at the same time using lazy loading? (each page has own module)

Thank you very much!

Definitely going to donate after resolving this issues ;-)

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.