CodeSOD: Break my Validation

This post was originally published on this site

The Daily WTF

Linda inherited an inner-platform front-end framework. It was the kind of UI framework with an average file size of 1,000 lines of code, and an average test coverage of 0%.

Like most UI frameworks, it had a system for doing client side validation. Like most inner-platform UI frameworks, the validation system was fragile, confusing, and impossible to understand.

This code illustrates some of the problems:

/** * Modify a validator key, e.g change minValue or disable required * * @param fieldName * @param validatorKey – of the specific validator * @param key – the key to change * @param value – the value to set */ modifyValidatorValue: function (fieldName, validatorKey, key, value) { if (!helper.isNullOrUndefined(fieldName)) { // Iterate over fields for (var i in this.fields) { if (this.fields.hasOwnProperty(i)) { var field = this.fields[i]; if (field.name === fieldName) { if (!helper.isNullOrUndefined(validatorKey)) { if (field.hasOwnProperty(‘validators’)) { // Iterate over validators for

To read the full article click on the 'post' link at the top.