Skip to content

Commit

Permalink
Merge pull request #16861 from tienifr/fix/16611
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperhuangg authored Apr 7, 2023
2 parents d300d6e + e5aad43 commit 64f4a78
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,23 @@ class Form extends React.Component {
* @returns {Object} - An object containing the errors for each inputID, e.g. {inputID1: error1, inputID2: error2}
*/
validate(values) {
const trimmedStringValues = {};
_.each(values, (inputValue, inputID) => {
if (_.isString(inputValue)) {
(trimmedStringValues[inputID] = inputValue.trim());
} else {
trimmedStringValues[inputID] = inputValue;
}
});

FormActions.setErrors(this.props.formID, null);
FormActions.setErrorFields(this.props.formID, null);

// Run any validations passed as a prop
const validationErrors = this.props.validate(values);
const validationErrors = this.props.validate(trimmedStringValues);

// Validate the input for html tags. It should supercede any other error
_.each(values, (inputValue, inputID) => {
_.each(trimmedStringValues, (inputValue, inputID) => {
// Return early if there is no value OR the value is not a string OR there are no HTML characters
if (!inputValue || !_.isString(inputValue) || inputValue.search(CONST.VALIDATE_FOR_HTML_TAG_REGEX) === -1) {
return;
Expand Down

0 comments on commit 64f4a78

Please sign in to comment.