MCPcopy Index your code
hub / github.com/bitnbytesio/node-input-validator / validateRequiredWith

Method validateRequiredWith

lib/rules.js:112–140  ·  view source on GitHub ↗

* * @param {*} field * @param {*} value * @param {*} args

(field, value, args)

Source from the content-addressed store, hash-verified

110 * @param {*} args
111 */
112 async validateRequiredWith(field, value, args) {
113
114 if (!Array.isArray(args)) args = [args];
115
116 if (!args.length) {
117 throw new Error('Invalid arguments supplied for field ' + field + ' in required with rule.');
118 }
119
120 let i, required = false;
121
122 for (i = 0; i < args.length; ++i) {
123
124 if (args[i] == field) {
125 continue;
126 }
127
128 if (!this.isEmpty(this.validator.inputs[args[i]])) {
129 required = true;
130 break;
131 }
132 }
133
134 if (required && this.isEmpty(value)) {
135
136 return false;
137 }
138
139 return true;
140 }
141
142 /**
143 *

Callers

nothing calls this directly

Calls 1

isEmptyMethod · 0.95

Tested by

no test coverage detected