Skip to content

Commit

Permalink
Password field fix (#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz authored Feb 24, 2020
1 parent 92b8fc4 commit 1910ed3
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions packages/fields/src/types/Password/views/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ const PasswordField = ({ onChange, autoFocus, field, value: serverValue, errors,
const [inputConfirm, setInputConfirm] = useState('');

useEffect(() => {
onChange({
inputPassword,
inputConfirm,
});
if (isEditing) {
onChange({
inputPassword,
inputConfirm,
});
}
}, [inputPassword, inputConfirm]);

useEffect(() => {
Expand All @@ -40,6 +42,17 @@ const PasswordField = ({ onChange, autoFocus, field, value: serverValue, errors,
setShowInputValue(!showInputValue);
};

const renderErrors = src => {
const appearance = src === errors ? 'danger' : 'warning';

return src.map(({ message, data }) => (
<Alert appearance={appearance} key={message}>
{message}
{data ? ` - ${JSON.stringify(data)}` : null}
</Alert>
));
};

const value = serverValue || '';
const htmlID = `ks-input-${field.path}`;

Expand Down Expand Up @@ -88,23 +101,8 @@ const PasswordField = ({ onChange, autoFocus, field, value: serverValue, errors,
)}
</FieldInput>

{errors.length
? errors.map(({ message, data }) => (
<Alert appearance="danger" key={message}>
{message}
{data ? ` - ${JSON.stringify(data)}` : null}
</Alert>
))
: null}

{warnings.length
? warnings.map(({ message, data }) => (
<Alert appearance="warning" key={message}>
{message}
{data ? ` - ${JSON.stringify(data)}` : null}
</Alert>
))
: null}
{renderErrors(errors)}
{renderErrors(warnings)}
</FieldContainer>
);
};
Expand Down

0 comments on commit 1910ed3

Please sign in to comment.