Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/fwf 3911 formbuilder modal #337

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface CustomButtonProps {
variant: string;
size?: "sm" | "md" | "lg" ;
label: string;
name?: string,
onClick?: () => void;
isDropdown?: boolean;
dropdownItems?: DropdownItem[];
Expand All @@ -38,6 +39,7 @@ export const CustomButton: React.FC<CustomButtonProps> = ({
className = "",
dataTestid = "",
ariaLabel = "",
name = "",
buttonLoading = false,
}) => {
const buttonRef = useRef<HTMLButtonElement>(null);
Expand Down Expand Up @@ -80,6 +82,7 @@ export const CustomButton: React.FC<CustomButtonProps> = ({
ref={buttonRef}
data-testid={dataTestid}
aria-label={ariaLabel}
name={name}
className={`${size !== 'md' ? className : `btn-md ${className}`}`}
>
{label}
Expand Down Expand Up @@ -117,6 +120,7 @@ export const CustomButton: React.FC<CustomButtonProps> = ({
size={size!='md' ? size : undefined}
onClick={onClick}
disabled={disabled || buttonLoading}
name={name}
className={`${size !== 'md' ? className : `btn-md ${className}`}`}
data-testid={dataTestid}
aria-label={ariaLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ export const FormBuilderModal: React.FC<BuildFormModalProps> = React.memo(
setValues(prev => ({...prev,[name]:value}))
}

const handleOnBlur = ()=>{
if(!values.title || values.title !== cachedTitle){
nameValidationOnBlur(values)
const handleOnBlur = (e)=>{
//TBD: need to prevent this function on modal close
const relatedTargetName = e.relatedTarget?.name;
const createButtonClicked = relatedTargetName == "createButton";
const isCancelButton = relatedTargetName == "cancelButton";
if((!values.title || values.title !== cachedTitle) && !isCancelButton){
nameValidationOnBlur({...values,createButtonClicked})
setCachedTitle(values.title);
}
}
Expand All @@ -103,6 +107,10 @@ export const FormBuilderModal: React.FC<BuildFormModalProps> = React.memo(
setValues({title:"",description:"", display: checked ? "wizard" : "form" })
setCachedTitle('');
}
if(showBuildForm){
//reset the name error on starting
setNameError("");
}
},[showBuildForm])

return (
Expand Down Expand Up @@ -176,13 +184,15 @@ export const FormBuilderModal: React.FC<BuildFormModalProps> = React.memo(
label={primaryBtnLabel}
buttonLoading={isLoading}
onClick={handlePrimaryAction} // Use the new handler
name="createButton"
dataTestid={primaryBtndataTestid}
ariaLabel={primaryBtnariaLabel}
/>

<CustomButton
variant="secondary"
size="md"
name="cancelButton"
label={secondaryBtnLabel}
onClick={secondaryBtnAction}
dataTestid={secondoryBtndataTestid}
Expand Down
Loading