Sha256: e57cc1b064facd3d5e788b56f5afa2daeabaaa53266ae7710118c5b0f5fd2722

Contents?: true

Size: 1.7 KB

Versions: 638

Compression:

Stored size: 1.7 KB

Contents

import React, { useEffect, useState } from "react";
import { Button, FixedConfirmationToast, PhoneNumberInput } from "../../";

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

638 entries across 638 versions & 2 rubygems

Version Path
playbook_ui_docs-13.30.0.pre.alpha.PBNTR353draggablev53136 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.30.0.pre.alpha.PBNTR353draggablev53136 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.30.0.pre.alpha.PLAY1328fixtimelinekitglobalpropsreact3096 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.30.0.pre.alpha.PLAY1328fixtimelinekitglobalpropsreact3096 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.30.0 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.29.0.pre.alpha.removeduplicatekitexampleclass3063 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.29.0.pre.alpha.removeduplicatekitexampleclass3063 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.29.0.pre.alpha.PBNTR329draggablev33060 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.29.0.pre.alpha.PBNTR329draggablev33060 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.29.0.pre.alpha.PBNTR329draggablev33059 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.29.0.pre.alpha.PBNTR329draggablev33059 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.29.0.pre.alpha.testingcollapsibleissue3052 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.29.0.pre.alpha.testingcollapsibleissue3052 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.29.0 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.28.0.pre.alpha.PBNTR297gradientoverlay3029 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.28.0.pre.alpha.PBNTR297gradientoverlay3029 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.28.0.pre.alpha.pbntr312tableheaderflexremoval3019 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.28.0.pre.alpha.pbntr312tableheaderflexremoval3019 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.28.0.pre.alpha.dialogturbostreameventlistener3017 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.28.0.pre.alpha.dialogturbostreameventlistener3017 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx