From 1910ed313de9326f7cee97b1ccdb5cae23d53e90 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Mon, 24 Feb 2020 13:41:13 +1100 Subject: [PATCH] Password field fix (#2421) --- .../fields/src/types/Password/views/Field.js | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/fields/src/types/Password/views/Field.js b/packages/fields/src/types/Password/views/Field.js index f90580f204a..5170ad8a63d 100644 --- a/packages/fields/src/types/Password/views/Field.js +++ b/packages/fields/src/types/Password/views/Field.js @@ -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(() => { @@ -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 }) => ( + + {message} + {data ? ` - ${JSON.stringify(data)}` : null} + + )); + }; + const value = serverValue || ''; const htmlID = `ks-input-${field.path}`; @@ -88,23 +101,8 @@ const PasswordField = ({ onChange, autoFocus, field, value: serverValue, errors, )} - {errors.length - ? errors.map(({ message, data }) => ( - - {message} - {data ? ` - ${JSON.stringify(data)}` : null} - - )) - : null} - - {warnings.length - ? warnings.map(({ message, data }) => ( - - {message} - {data ? ` - ${JSON.stringify(data)}` : null} - - )) - : null} + {renderErrors(errors)} + {renderErrors(warnings)} ); };