.pragma library

function validateRequired(fields, paramsJson) {
    var params = JSON.parse(paramsJson)
    for (var i = 0; i < fields.length; i++) {
        var f = fields[i]
        var val = params[f.key]
        if (f.required && (val === undefined || val === null || val === "" || (typeof val === "string" && val.length === 0))) {
            return (f.label || f.key) + " is required"
        }
    }
    return ""
}
