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.34.1.pre.alpha.play1407statvaluekitinconsistencies3388 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.1.pre.alpha.play1407statvaluekitinconsistencies3388 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.34.1.pre.alpha.PLAY14703378 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.1.pre.alpha.PLAY14703378 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.34.1 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.1 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3370 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3370 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3369 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3369 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3368 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3366 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3366 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.34.0 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.33.1.pre.alpha.play1407statvaluekitinconsistencies3352 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.33.1.pre.alpha.play1407statvaluekitinconsistencies3352 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.33.1.pre.alpha.PLAY14063320 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.33.1.pre.alpha.PLAY14063320 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui-13.33.1 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx
playbook_ui_docs-13.33.0.pre.alpha.PBNTR405dropdownformfixesrails3311 app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.jsx