Skip to content

Commit

Permalink
Wizrad: add condition to useHostnameValidation in case of empty string
Browse files Browse the repository at this point in the history
this adds condition to useHostnameValidation in case of empty string
if user decide to delete the value in hostname field
  • Loading branch information
mgold1234 committed Feb 18, 2025
1 parent 0c8b6b3 commit 61d3608
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Components/CreateImageWizard/ValidatedInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import {
HelperText,
Expand Down Expand Up @@ -103,7 +103,8 @@ export const HookValidatedInput = ({
inputType,
warning = undefined,
}: HookValidatedInputPropTypes) => {
const [isPristine, setIsPristine] = useState(!value ? true : false);
const isEmpty = value === undefined || value === null || value === '';
const [isPristine, setIsPristine] = useState(isEmpty);
// Do not surface validation on pristine state components
// Allow step validation to be set on pristine state, when needed
const validated = isPristine
Expand All @@ -115,9 +116,19 @@ export const HookValidatedInput = ({
: 'success';

const handleBlur = () => {
setIsPristine(false);
if (isEmpty) {
setIsPristine(true);
} else {
setIsPristine(false);
}
};

useEffect(() => {
if (isEmpty) {
setIsPristine(true);
}
}, [value, setIsPristine]);

return (
<>
{inputType === 'textArea' ? (
Expand Down

0 comments on commit 61d3608

Please sign in to comment.