UNPKG

@salesforce/soql-model

Version:
37 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PicklistValidator = void 0; /* * Copyright (c) 2021, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ const messages_1 = require("../messages/messages"); const validator_1 = require("./validator"); class PicklistValidator extends validator_1.Validator { validate(input) { let isValid = true; let message; if (this.options.picklistValues) { const validValues = [...this.options.picklistValues]; if (this.options.nillable) { validValues.push('null'); } isValid = validValues.includes(input); if (!isValid) { const commaSeparatedValues = validValues.reduce((soFar, next) => { if (soFar.length > 0) { soFar += ', '; } soFar += next; return soFar; }); message = messages_1.Messages.error_fieldInput_picklist.replace('{0}', commaSeparatedValues); } } return { isValid, message }; } } exports.PicklistValidator = PicklistValidator; //# sourceMappingURL=picklistValidator.js.map