/** * WordPress dependencies */ import { __ } from "@wordpress/i18n"; import { useBlockProps, RichText, InnerBlocks } from "@wordpress/block-editor"; import { useEffect, useState, useRef } from "@wordpress/element"; import { select, dispatch, useSelect } from "@wordpress/data"; /** * Internal dependencies */ const { duplicateBlockIdFix, filterBlocksByName, getBlockParentClientId, EBDisplayIcon, DynamicInputValueHandler, BlockProps } = EBControls; import classnames from "classnames"; import Inspector from "./inspector"; import Style from "./style"; export default function Edit(props) { const { attributes, setAttributes, isSelected, clientId, className, name, } = props; const { resOption, blockMeta, parentBlockId, blockId, classHook, showLabel, labelText, fieldName, defaultValue, placeholderText, isRequired, validationMessage, validationRules, numberValidationMessage, isIcon, icon, formStyle, parentBlockPaddingLeft, parentBlockPaddingUnit, parentBlockIconSize, parentIconColor, } = attributes; // you must declare this variable const enhancedProps = { ...props, blockPrefix: 'eb-number-field', rootClass: "eb-guten-block-main-parent-wrapper eb-form-field", style: }; //UseEffect for set Validation rules useEffect(() => { const rules = { [fieldName]: { isRequired: { status: isRequired, message: validationMessage, }, isNumber: { message: numberValidationMessage, }, }, }; setAttributes({ validationRules: rules }); }, [isRequired, fieldName, validationMessage]); return ( <> {isSelected && ( )} {showLabel && formStyle != "form-style-modern" && ( <> setAttributes({ labelText }) } readOnly={true} />{" "} {isRequired && ( * )} > )} {isIcon && icon && } {formStyle == "form-style-modern" && ( <> {labelText}{" "} {isRequired && ( * )} > )} {isRequired && ( <> {validationMessage} > )} > ); }