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

Password field fix #2421

Merged
merged 3 commits into from
Feb 24, 2020
Merged
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
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