Sha256: 47627a1bc91881a413a909980e0970970e9a4f67f35c692d3d94e1c685aea886

Contents?: true

Size: 1.71 KB

Versions: 948

Compression:

Stored size: 1.71 KB

Contents

import React, { useEffect, useState } from "react";
import { Button, FixedConfirmationToast, PhoneNumberInput } from "playbook-ui";

const PhoneNumberInputValidation = (props) => {
    const [formErrors, setFormErrors] = useState("");
    const [showFormErrors, setShowFormErrors] = useState(false);
    const [phoneNumber, setPhoneNumber] = useState("");
    const [countryCode, setCountryCode] = useState("af");

    const handleOnValidate = (valid) => {
        setFormErrors(
            valid ? "" : "Please correct the fields below and try again."
        );
    };

    const handleOnChange = ({ iso2, number }) => {
        setCountryCode(iso2);
        setPhoneNumber(number);
    };
    
    const handleOnSubmit = (e) => {
        if (showFormErrors) e.preventDefault()
    }

    useEffect(() => {
        setShowFormErrors(formErrors.length > 0);
    }, [formErrors]);

    return (
        <form
            action=""
            method="get"
            onSubmit={handleOnSubmit}
        >
            {showFormErrors && (
                <FixedConfirmationToast
                    marginBottom="md"
                    status="error"
                    text={formErrors}
                />
            )}
            <PhoneNumberInput
                error="Missing phone number."
                id="validation"
                initialCountry={countryCode}
                onChange={handleOnChange}
                onValidate={handleOnValidate}
                required
                value={phoneNumber}
                {...props}
            />
            <Button
                htmlType="submit"
                text="Save Phone Number"
            />
        </form>
    );
};

export default PhoneNumberInputValidation;

Version data entries

948 entries across 948 versions & 2 rubygems

Version Path
playbook_ui_docs-14.11.1.pre.alpha.PLAY17445539 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.11.1.pre.alpha.PLAY17445539 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.11.1.pre.alpha.PBNTR798datepickerturbo5537 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.11.1.pre.alpha.PBNTR798datepickerturbo5537 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.11.1.pre.alpha.pbntr703collapsiblerowsrails5536 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.11.1.pre.alpha.pbntr703collapsiblerowsrails5536 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.11.1.pre.alpha.PLAY1751pbcontenttagpt25529 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.11.1.pre.alpha.PLAY1751pbcontenttagpt25529 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.11.1.pre.alpha.PBNTR7495495 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.11.1.pre.alpha.PBNTR7495495 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.12.0.pre.rc.11 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.12.0.pre.rc.11 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.12.0.pre.rc.10 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.12.0.pre.rc.10 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.12.0.pre.rc.9 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.12.0.pre.rc.9 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.12.0.pre.rc.8 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.12.0.pre.rc.8 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-14.12.0.pre.rc.7 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-14.12.0.pre.rc.7 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx