gd-sprest-bs 9.2.4 → 9.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -567,7 +567,9 @@ var Field = function (props) {
567
567
  case gd_sprest_1.SPTypes.FieldType.User:
568
568
  // Set the type
569
569
  controlProps.type = isReadonly ? core_1.Components.FormControlTypes.Readonly : peoplePicker_1.PeoplePickerControlType;
570
- // Set the flag to allow multiple selections
570
+ // Update the properties, based on the field settings
571
+ controlProps.allowGroups = props.field.SelectionGroup == gd_sprest_1.SPTypes.FieldUserSelectionType.PeopleAndGroups;
572
+ controlProps.groupId = props.field.SelectionGroup;
571
573
  controlProps.multi = props.field.AllowMultipleValues;
572
574
  // Set the rendered event
573
575
  onControlRendered = controlProps.onControlRendered;
@@ -665,7 +665,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));
665
665
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
666
666
 
667
667
  "use strict";
668
- eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.Field = void 0;\n\nvar gd_sprest_1 = __webpack_require__(/*! gd-sprest */ \"./node_modules/.pnpm/gd-sprest@6.8.6/node_modules/gd-sprest/build/index.js\");\n\nvar core_1 = __webpack_require__(/*! ../core */ \"./build/components/core.js\");\n\nvar datetime_1 = __webpack_require__(/*! ../datetime */ \"./build/components/datetime/index.js\");\n\nvar peoplePicker_1 = __webpack_require__(/*! ../peoplePicker */ \"./build/components/peoplePicker/index.js\");\n/**\r\n * Field\r\n */\n\n\nvar Field = function Field(props) {\n var control;\n var lookupFieldInfo = null;\n var mmsFieldInfo = null; // Method to get the choice options\n\n var getChoiceItems = function getChoiceItems(isCheckbox, field, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the choices\n\n for (var i = 0; i < field.Choices.results.length; i++) {\n var choice = field.Choices.results[i];\n var isSelected = false; // Determine if this choice is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n // See if this choice is selected\n if (choice == selectedValues[j]) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // See if this is a checkbox\n\n\n if (isCheckbox) {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice\n });\n } else {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice,\n text: choice,\n value: choice\n });\n }\n } // See if this is a dropdown and no selected values exists, and this is a required field\n\n\n if (!isCheckbox && items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the file extension\n\n\n var getFileExtension = function getFileExtension(fileName) {\n if (fileName === void 0) {\n fileName = \"\";\n }\n\n var extension = fileName.split('.');\n return extension[extension.length - 1].toLowerCase();\n }; // Method to generate the lookup dropdown items\n\n\n var getLookupItems = function getLookupItems(field, lookupItems, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the lookup items\n\n for (var i = 0; i < lookupItems.length; i++) {\n var item = lookupItems[i];\n var isSelected = false; // Determine if this lookup is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n var id = selectedValues[j] && selectedValues[j].Id ? selectedValues[j].Id : selectedValues[j]; // See if this choice is selected\n\n if (item.Id == id) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // Add the item\n\n\n items.push({\n data: item,\n isSelected: isSelected,\n text: item[field.LookupField],\n value: item.Id.toString()\n });\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the mms dropdown items\n\n\n var getMMSItems = function getMMSItems(term, selectedValues, isRoot) {\n if (selectedValues === void 0) {\n selectedValues = [];\n }\n\n if (isRoot === void 0) {\n isRoot = true;\n }\n\n var items = []; // See if information exists\n\n if (term.info && !isRoot) {\n var isSelected = false; // Parse the selected values\n\n for (var i = 0; i < selectedValues.length; i++) {\n // See if this item is selected\n if (selectedValues[i] == term.info.id) {\n isSelected = true;\n break;\n }\n } // Add the heading\n\n\n items.push({\n data: term,\n isSelected: isSelected,\n text: term.info.name,\n value: term.info.id\n });\n } // Parse the terms\n\n\n for (var termName in term) {\n var child = term[termName]; // Skip the info and parent properties\n\n if (termName == \"info\" || termName == \"parent\") {\n continue;\n } // Get the child items\n\n\n var childItems = getMMSItems(child, selectedValues, false); // Add the item\n\n items = items.concat(childItems);\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && isRequired) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Set the properties based on the field link\n\n\n var fieldLink = props.listInfo.fieldLinks ? props.listInfo.fieldLinks[props.field.InternalName] : null;\n var isReadonly = fieldLink && typeof fieldLink.ReadOnly === \"boolean\" ? fieldLink.ReadOnly : props.field.ReadOnlyField;\n var isRequired = fieldLink && typeof fieldLink.Required === \"boolean\" ? fieldLink.Required : props.field.Required; // See if this is an internal field\n\n if (props.field.CanBeDeleted == false) {\n // Override the property based on the field property\n isReadonly = isReadonly || props.field.ReadOnlyField;\n } // Set the default properties for the control\n\n\n var controlProps = {\n description: props.field.Description,\n errorMessage: props.errorMessage,\n id: props.field.InternalName,\n isReadonly: isReadonly,\n label: (isRequired ? \"* \" : \"\") + props.field.Title,\n name: props.field.InternalName,\n onControlRendering: function onControlRendering(control) {\n // Execute the event\n return props.onControlRendering ? props.onControlRendering(control, props.field) : null;\n },\n onControlRendered: function onControlRendered(formControl) {\n // Save the control\n control = formControl; // Execute the event\n\n return props.onControlRendered ? props.onControlRendered(control, props.field) : null;\n },\n required: isRequired,\n type: core_1.Components.FormControlTypes.TextField,\n value: props.value\n }; // Define a base validation method\n\n var baseValidation = null; // See if this is a new form, a default value exists and no value has been defined\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New && props.field.DefaultValue && props.value == null) {\n // Set the default value\n controlProps.value = props.field.DefaultValue;\n } // Set the type\n\n\n var onControlRendered = null;\n var onControlRendering = null;\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Checkbox; // Create the item\n\n controlProps.items = [{\n label: controlProps.label\n }]; // Clear the label\n\n controlProps.label = \"\";\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n var displayRadioButtons = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // See if we are displaying radio buttons\n\n if (displayRadioButtons) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Switch;\n } else {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown;\n } // Get the items\n\n\n var items = getChoiceItems(displayRadioButtons, props.field, props.value); // See if this is not a required field\n\n if (!isRequired) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items;\n break;\n // Currency Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.TextField; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Call the event\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Set the time flag\n var showTime = props.field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime;\n controlProps.showTime = showTime; // Set the type\n\n controlProps.type = datetime_1.DateTimeControlType; // See if there is a formula and this is a new form\n\n var dtValue = (props.field.DefaultFormula || props.field.DefaultValue || \"\").toLowerCase();\n\n if (dtValue && props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var idx = dtValue.indexOf(\"today\"); // See if the date is a formula\n\n if (idx >= 0) {\n var dtNow = new Date(Date.now()); // See if we are adding days\n\n var daysIdx = dtValue.indexOf(\"+\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() + days);\n }\n } // See if we are subtracting days\n\n\n daysIdx = dtValue.indexOf(\"-\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() - days);\n }\n } // Set the value\n\n\n controlProps.value = dtNow;\n } else {\n // Set the value\n controlProps.value = new Date(dtValue);\n }\n }\n\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Default the lookup field props will determine the default type\n controlProps.type = props.field.AllowMultipleValues ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // See if this field is readonly and a value exists\n\n if (isReadonly) {\n // Update the value\n controlProps.type = core_1.Components.FormControlTypes.Readonly; // Ensure a value exists\n\n if (props.value) {\n // Set the rendered event\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n };\n }\n } else {\n // Set the rendering event\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Display a loading message\n\n controlProps.loadingMessage = \"Loading the Lookup Data\"; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Load the field information\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n lookupFieldInfo = fieldInfo; // Set the lookup filter\n\n lookupFieldInfo.lookupFilter = controlProps.lookupFilter; // Update the multi property\n\n controlProps.multi = lookupFieldInfo.multi; // Get the drop down information\n\n gd_sprest_1.Helper.ListFormField.loadLookupData(lookupFieldInfo, 500).then( // Success\n function (items) {\n // Get the dropdown items\n var ddlItems = getLookupItems(props.field, items, props.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !lookupFieldInfo.multi) {\n // Add a blank entry\n ddlItems = [{\n text: \"\",\n value: null\n }].concat(ddlItems);\n } // Set the items\n\n\n controlProps.items = ddlItems; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Clear the value, since the getLookupItems method takes care of this for us\n\n controlProps.value = null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the lookup field values for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the field information for field '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n controlProps.el.innerHTML = \"\";\n core_1.Components.Alert({\n el: controlProps.el,\n content: \"Error loading the lookup field information.\",\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n });\n };\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var isChoice = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // Set the type\n\n controlProps.type = isChoice ? core_1.Components.FormControlTypes.MultiSwitch : core_1.Components.FormControlTypes.MultiDropdown; // Update the value\n\n controlProps.value = (props.value ? props.value.results : null) || props.value; // Set the items\n\n controlProps.items = getChoiceItems(isChoice, props.field, props.value);\n break;\n // Note\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the properties\n controlProps.type = core_1.Components.FormControlTypes.TextArea;\n controlProps.rows = props.field.NumberOfLines;\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField_1 = props.field;\n var numberProps = controlProps; // Set the default value\n\n numberProps.value = numberProps.value == null ? numberField_1.DefaultValue : numberProps.value; // See if this is a percentage\n\n var isPercent = numberField_1.ShowAsPercentage;\n\n if (isPercent == null) {\n // Set the value from the schema (2013 environments)\n isPercent = numberField_1.SchemaXml.toLowerCase().indexOf('percentage=\"true\"') > 0;\n }\n\n if (isPercent) {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.Range; // Default the max\n\n numberProps.max = numberField_1.MaximumValue == 1 || numberField_1.MaximumValue == Number.MAX_VALUE ? 100 : numberField_1.MaximumValue; // Set the min value\n\n numberProps.min = numberField_1.MinimumValue == -1.7976931348623157e+308 ? 0 : numberField_1.MinimumValue; // Set the value\n\n numberProps.value = numberProps.value == null || numberProps.value == Number.MIN_VALUE ? 0 : numberProps.value;\n numberProps.value = numberProps.value * (numberProps.max == 100 && numberProps.value < 1 ? 100 : 1);\n } // Else, see if the min/max values are defined\n else if (typeof numberField_1.MaximumValue == \"number\" && numberField_1.MaximumValue != Number.MAX_VALUE && typeof numberField_1.MinimumValue == \"number\" && numberField_1.MinimumValue != Number.MIN_VALUE) {\n // Update the properties to display a range\n numberProps.type = core_1.Components.FormControlTypes.Range;\n numberProps.max = numberField_1.MaximumValue;\n numberProps.min = numberField_1.MinimumValue;\n numberProps.value = typeof numberProps.value == \"number\" ? numberProps.value : numberProps.min; // Set validation\n\n if (numberField_1.MinimumValue || numberField_1.MaximumValue) {\n // Add validation\n baseValidation = function baseValidation(control, result) {\n // Ensure the value is a number\n if (/^[0-9]*$/.test(result.value) == false) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be a number.\";\n return result;\n } // Validate the min value\n\n\n if (numberField_1.MinimumValue && result.value < numberField_1.MinimumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be greater than or equal to \" + numberField_1.MinimumValue;\n return result;\n } // Validate the max value\n\n\n if (numberField_1.MaximumValue && result.value > numberField_1.MaximumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be less than or equal to \" + numberField_1.MaximumValue;\n return result;\n } // Valid\n\n\n result.isValid = true; // Return the result\n\n return result;\n };\n }\n } else {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.TextField;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n var desc_1 = null;\n var url_1 = null;\n var value_1 = props.value; // See if a value exists\n\n if (props.value) {\n // Update the value\n controlProps.value = props.value.Url;\n } // Set the render event\n\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Clear the element\n\n control.el.innerHTML = \"\"; // See if we are rendering the description\n\n var showDesc = controlProps.showDescription;\n showDesc = typeof showDesc === \"boolean\" ? showDesc : true;\n\n if (showDesc) {\n // Render the description\n desc_1 = core_1.Components.FormControl({\n className: \"mb-1\",\n el: control.el,\n placeholder: \"Description\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Description : null\n });\n } // Render the url\n\n\n url_1 = core_1.Components.FormControl({\n el: control.el,\n placeholder: \"Url\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Url : null\n }); // Set the get value event\n\n control.props.onGetValue = function () {\n // Return the value\n return {\n Description: desc_1 ? desc_1.getValue() : url_1.getValue(),\n Url: url_1.getValue()\n };\n }; // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n }; // Set the validate event\n\n\n baseValidation = function baseValidation(control, result) {\n var descValid,\n urlValid = false; // Get the form control elements\n\n var elFormControl = control.el.querySelectorAll(\".form-control\"); // See if both the description and url are displayed\n\n var elDesc = null;\n var elUrl = null;\n\n if (elFormControl.length > 1) {\n // Set the elements\n elDesc = elFormControl[0];\n elUrl = elFormControl[1];\n } else {\n // Set the elements\n elUrl = elFormControl[0]; // Set the flag\n\n descValid = true;\n } // See if the description exists\n\n\n if (elDesc) {\n // Clear the classes\n elDesc.classList.remove(\"is-invalid\");\n elDesc.classList.remove(\"is-valid\"); // Set the flag\n\n descValid = control.props.required ? desc_1.getValue() ? true : false : true; // Set the class\n\n elDesc.classList.add(descValid ? \"is-valid\" : \"is-invalid\");\n } // See if the url exists\n\n\n if (elUrl) {\n // Clear the classes\n elUrl.classList.remove(\"is-invalid\");\n elUrl.classList.remove(\"is-valid\"); // Set the flag\n\n urlValid = control.props.required ? url_1.getValue() ? true : false : true; // Set the class\n\n elUrl.classList.add(urlValid ? \"is-valid\" : \"is-invalid\");\n } // Set the validation falg\n\n\n result.isValid = descValid && urlValid; // Return the result\n\n return result;\n };\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n controlProps.type = isReadonly ? core_1.Components.FormControlTypes.Readonly : peoplePicker_1.PeoplePickerControlType; // Set the flag to allow multiple selections\n\n controlProps.multi = props.field.AllowMultipleValues; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // See if this field is readonly and a value exists\n\n if (props.value && isReadonly) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n } // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n } // See if this is the document name field\n\n\n if (props.field.InternalName == \"FileLeafRef\") {\n // Set base validation\n baseValidation = function baseValidation(control, result) {\n var value = result.value; // Ensure the value exists\n\n result.isValid = value ? true : false;\n\n if (result.isValid) {\n // See if it ends w/ a .\n if (value[value.length - 1] == '.') {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot end with a '.' character.\";\n } // Else, see if it contains invalid characters\n else if (/[~\"\\#\\%\\&\\*\\:\\<\\>\\?\\/\\\\\\{\\|\\}\"]/.test(value) || value.indexOf('\\\\') >= 0) {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot contain the following characters: ~ \\\" # % & * : < > ? / \\\\ { | }\";\n } // Else, see if we are changing the extension\n else if (control.props.value) {\n // Get the file extensions\n var origExtension = getFileExtension(control.props.value);\n var newExtension = getFileExtension(value); // Update the validation\n\n result.isValid = origExtension == newExtension;\n result.invalidMessage = \"The file extension cannot be changed. It must end with '.\" + origExtension + \"'\";\n }\n } // Return the validation result\n\n\n return result;\n };\n } // See if this is a taxonomy field\n\n\n if (/^TaxonomyFieldType/.test(props.field.TypeAsString)) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown; // Set a render event\n\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Display a loading message\n controlProps.loadingMessage = \"Loading the MMS Data\"; // Load the field information\n\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n mmsFieldInfo = fieldInfo; // Set the type\n\n controlProps.type = mmsFieldInfo.multi ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // Load the value field\n\n gd_sprest_1.Helper.ListFormField.loadMMSValueField(mmsFieldInfo).then( // Success\n function (valueField) {\n // Set the value field\n mmsFieldInfo.valueField = valueField; // See if this is a new form\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var fieldValue = []; // Get the default values\n\n var values = (props.field.DefaultValue || \"\").split(\";#\");\n\n for (var i = 0; i < values.length; i++) {\n var value = values[i].split(\"|\");\n\n if (value.length == 2) {\n // Add the term id\n fieldValue.push(value[1]);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } else {\n var fieldValue = props.value; // Get the field value\n\n var values = fieldValue && fieldValue.results ? fieldValue.results : [fieldValue]; // Clear the field values\n\n fieldValue = []; // Parse the values\n\n for (var i = 0; i < values.length; i++) {\n // Ensure the value exists\n if (values[i] && values[i].TermGuid) {\n // Add the value\n fieldValue.push(values[i].TermGuid);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } // Load the terms\n\n\n gd_sprest_1.Helper.ListFormField.loadMMSData(mmsFieldInfo).then( // Success\n function (terms) {\n // Get the items\n var items = getMMSItems(gd_sprest_1.Helper.Taxonomy.toObject(terms), controlProps.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !mmsFieldInfo.multi) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms terms for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms value field for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n }, function (msg) {\n // Display an error message\n core_1.Components.Alert({\n el: controlProps.el,\n content: msg,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(msg) : null;\n });\n });\n };\n } // Create the field\n\n\n var field = {\n control: control,\n controlProps: controlProps,\n getValue: function getValue() {\n var fieldValue = {\n name: props.field.InternalName,\n value: control ? control.getValue() : null\n }; // Update the field name/value, based on the type\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Update the value\n fieldValue.value = fieldValue.value ? true : false;\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.Dropdown) {\n // See if there is a value\n var ddlValue = fieldValue.value;\n\n if (ddlValue) {\n // Update the field value\n fieldValue.value = ddlValue.value || ddlValue.text;\n }\n } else {\n // See if there is a value\n var cbValue = fieldValue.value;\n\n if (cbValue) {\n // Update the field value\n fieldValue.value = cbValue.label;\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value || null;\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value ? fieldValue.value.toISOString() : null;\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (lookupFieldInfo.multi) {\n var values_1 = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values_1.length; j++) {\n // Add the value\n fieldValue.value.results.push(values_1[j].value || values_1[j].text);\n }\n } else {\n // Update the field value\n fieldValue.value = fieldValue.value ? fieldValue.value.value || fieldValue.value.text : null; // Ensure a value exists, otherwise null\n\n fieldValue.value = fieldValue.value || null;\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var values = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values.length; j++) {\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.MultiDropdown) {\n // See if there is a value\n var ddlValue = values[j]; // Add the values\n\n fieldValue.value.results.push(ddlValue.value || ddlValue.text);\n } else {\n // See if there is a value\n var cbValue = values[j]; // Add the values\n\n fieldValue.value.results.push(cbValue.label);\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField = props.field; // Ensure a field value exists\n\n if (fieldValue.value) {\n // See if this is a percentage\n if (numberField.ShowAsPercentage) {\n // Update the value\n fieldValue.value = fieldValue.value / 100;\n }\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n // See if the field value exists\n if (fieldValue.value && fieldValue.value.Url) {\n // Set the url, and validate the format\n var url = fieldValue.value.Url;\n\n if (url && /^http/.test(url.toLowerCase()) == false) {\n // Update the url, otherwise the request will fail\n url = \"https://\" + url;\n } // Add the metadata\n\n\n fieldValue.value = {\n __metadata: {\n type: \"SP.FieldUrlValue\"\n },\n Description: fieldValue.value.Description || \"\",\n Url: url\n };\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (props.field.AllowMultipleValues) {\n var values_2 = fieldValue.value || []; // Default the value\n\n fieldValue.value = {\n results: []\n }; // Parse the options\n\n for (var j = 0; j < values_2.length; j++) {\n var userValue = values_2[j]; // Add the field value\n\n userValue.Id ? fieldValue.value.results.push(userValue.Id) : null;\n }\n } else {\n var userValue = fieldValue.value ? fieldValue.value[0] : null; // Set the field value\n\n fieldValue.value = userValue && userValue.Id ? userValue.Id : null;\n }\n\n break;\n // MMS\n\n default:\n // See if this is a MMS field\n if (mmsFieldInfo) {\n // Update the field name to the value field\n fieldValue.name = mmsFieldInfo ? mmsFieldInfo.valueField.InternalName : fieldValue.name + \"_0\"; // See if this is a multi field\n\n if (mmsFieldInfo.multi) {\n // Parse the field values\n var fieldValues = fieldValue.value || [];\n fieldValue.value = [];\n\n for (var j = 0; j < fieldValues.length; j++) {\n var termInfo = fieldValues[j]; // Add the field value\n\n fieldValue.value.push(-1 + \";#\" + termInfo.text + \"|\" + termInfo.value);\n } // Set the field value\n\n\n fieldValue.value = fieldValue.value.join(\";#\");\n } else {\n // Set the value\n fieldValue.value = fieldValue.value && fieldValue.value.value ? -1 + \";#\" + fieldValue.value.text + \"|\" + fieldValue.value.value : \"\";\n }\n }\n\n break;\n } // Return the field value\n\n\n return fieldValue;\n },\n isValid: function isValid() {\n // See if there is base validation\n if (baseValidation) {\n // Validate the field\n var baseResult = baseValidation(control, {\n isValid: false,\n value: control.getValue()\n }); // Validate the current control\n\n var result = controlProps.onValidate ? controlProps.onValidate(controlProps, baseResult) : baseResult; // Return the flag\n\n if (typeof result === \"boolean\") {\n // Update the validation\n baseResult.isValid = result;\n control.updateValidation(control.el, baseResult); // Return the result\n\n return result;\n } // Update the validation\n\n\n control.updateValidation(control.el, result); // Return the flag\n\n return result.isValid;\n } // Validate the control\n\n\n return control ? control.isValid : false;\n }\n }; // Execute the assign to event\n\n props.assignTo ? props.assignTo(field) : null; // Return the field\n\n return field;\n};\n\nexports.Field = Field;\n\n//# sourceURL=webpack://gd-sprest-bs/./build/components/field/index.js?");
668
+ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.Field = void 0;\n\nvar gd_sprest_1 = __webpack_require__(/*! gd-sprest */ \"./node_modules/.pnpm/gd-sprest@6.8.6/node_modules/gd-sprest/build/index.js\");\n\nvar core_1 = __webpack_require__(/*! ../core */ \"./build/components/core.js\");\n\nvar datetime_1 = __webpack_require__(/*! ../datetime */ \"./build/components/datetime/index.js\");\n\nvar peoplePicker_1 = __webpack_require__(/*! ../peoplePicker */ \"./build/components/peoplePicker/index.js\");\n/**\r\n * Field\r\n */\n\n\nvar Field = function Field(props) {\n var control;\n var lookupFieldInfo = null;\n var mmsFieldInfo = null; // Method to get the choice options\n\n var getChoiceItems = function getChoiceItems(isCheckbox, field, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the choices\n\n for (var i = 0; i < field.Choices.results.length; i++) {\n var choice = field.Choices.results[i];\n var isSelected = false; // Determine if this choice is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n // See if this choice is selected\n if (choice == selectedValues[j]) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // See if this is a checkbox\n\n\n if (isCheckbox) {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice\n });\n } else {\n // Add the item\n items.push({\n isSelected: isSelected,\n label: choice,\n text: choice,\n value: choice\n });\n }\n } // See if this is a dropdown and no selected values exists, and this is a required field\n\n\n if (!isCheckbox && items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the file extension\n\n\n var getFileExtension = function getFileExtension(fileName) {\n if (fileName === void 0) {\n fileName = \"\";\n }\n\n var extension = fileName.split('.');\n return extension[extension.length - 1].toLowerCase();\n }; // Method to generate the lookup dropdown items\n\n\n var getLookupItems = function getLookupItems(field, lookupItems, selectedValues) {\n var items = []; // Update the selected values\n\n selectedValues = selectedValues && selectedValues.results ? selectedValues.results : [selectedValues]; // Parse the lookup items\n\n for (var i = 0; i < lookupItems.length; i++) {\n var item = lookupItems[i];\n var isSelected = false; // Determine if this lookup is selected\n\n for (var j = 0; j < selectedValues.length; j++) {\n var id = selectedValues[j] && selectedValues[j].Id ? selectedValues[j].Id : selectedValues[j]; // See if this choice is selected\n\n if (item.Id == id) {\n // Set the flag and break from the loop\n isSelected = true;\n break;\n }\n } // Add the item\n\n\n items.push({\n data: item,\n isSelected: isSelected,\n text: item[field.LookupField],\n value: item.Id.toString()\n });\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && field.Required) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Method to get the mms dropdown items\n\n\n var getMMSItems = function getMMSItems(term, selectedValues, isRoot) {\n if (selectedValues === void 0) {\n selectedValues = [];\n }\n\n if (isRoot === void 0) {\n isRoot = true;\n }\n\n var items = []; // See if information exists\n\n if (term.info && !isRoot) {\n var isSelected = false; // Parse the selected values\n\n for (var i = 0; i < selectedValues.length; i++) {\n // See if this item is selected\n if (selectedValues[i] == term.info.id) {\n isSelected = true;\n break;\n }\n } // Add the heading\n\n\n items.push({\n data: term,\n isSelected: isSelected,\n text: term.info.name,\n value: term.info.id\n });\n } // Parse the terms\n\n\n for (var termName in term) {\n var child = term[termName]; // Skip the info and parent properties\n\n if (termName == \"info\" || termName == \"parent\") {\n continue;\n } // Get the child items\n\n\n var childItems = getMMSItems(child, selectedValues, false); // Add the item\n\n items = items.concat(childItems);\n } // See if no selected values exists, and this is a required field\n\n\n if (items.length > 0 && selectedValues.length == 0 && isRequired) {\n // Select the first item\n items[0].isSelected = true;\n } // Return the items\n\n\n return items;\n }; // Set the properties based on the field link\n\n\n var fieldLink = props.listInfo.fieldLinks ? props.listInfo.fieldLinks[props.field.InternalName] : null;\n var isReadonly = fieldLink && typeof fieldLink.ReadOnly === \"boolean\" ? fieldLink.ReadOnly : props.field.ReadOnlyField;\n var isRequired = fieldLink && typeof fieldLink.Required === \"boolean\" ? fieldLink.Required : props.field.Required; // See if this is an internal field\n\n if (props.field.CanBeDeleted == false) {\n // Override the property based on the field property\n isReadonly = isReadonly || props.field.ReadOnlyField;\n } // Set the default properties for the control\n\n\n var controlProps = {\n description: props.field.Description,\n errorMessage: props.errorMessage,\n id: props.field.InternalName,\n isReadonly: isReadonly,\n label: (isRequired ? \"* \" : \"\") + props.field.Title,\n name: props.field.InternalName,\n onControlRendering: function onControlRendering(control) {\n // Execute the event\n return props.onControlRendering ? props.onControlRendering(control, props.field) : null;\n },\n onControlRendered: function onControlRendered(formControl) {\n // Save the control\n control = formControl; // Execute the event\n\n return props.onControlRendered ? props.onControlRendered(control, props.field) : null;\n },\n required: isRequired,\n type: core_1.Components.FormControlTypes.TextField,\n value: props.value\n }; // Define a base validation method\n\n var baseValidation = null; // See if this is a new form, a default value exists and no value has been defined\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New && props.field.DefaultValue && props.value == null) {\n // Set the default value\n controlProps.value = props.field.DefaultValue;\n } // Set the type\n\n\n var onControlRendered = null;\n var onControlRendering = null;\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Checkbox; // Create the item\n\n controlProps.items = [{\n label: controlProps.label\n }]; // Clear the label\n\n controlProps.label = \"\";\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n var displayRadioButtons = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // See if we are displaying radio buttons\n\n if (displayRadioButtons) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Switch;\n } else {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown;\n } // Get the items\n\n\n var items = getChoiceItems(displayRadioButtons, props.field, props.value); // See if this is not a required field\n\n if (!isRequired) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items;\n break;\n // Currency Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.TextField; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Call the event\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Set the time flag\n var showTime = props.field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime;\n controlProps.showTime = showTime; // Set the type\n\n controlProps.type = datetime_1.DateTimeControlType; // See if there is a formula and this is a new form\n\n var dtValue = (props.field.DefaultFormula || props.field.DefaultValue || \"\").toLowerCase();\n\n if (dtValue && props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var idx = dtValue.indexOf(\"today\"); // See if the date is a formula\n\n if (idx >= 0) {\n var dtNow = new Date(Date.now()); // See if we are adding days\n\n var daysIdx = dtValue.indexOf(\"+\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() + days);\n }\n } // See if we are subtracting days\n\n\n daysIdx = dtValue.indexOf(\"-\", idx);\n\n if (daysIdx > 0) {\n // Get the number of days to add\n var days = parseInt(dtValue.substr(daysIdx + 1));\n\n if (days > 0) {\n // Add the days\n dtNow.setDate(dtNow.getDate() - days);\n }\n } // Set the value\n\n\n controlProps.value = dtNow;\n } else {\n // Set the value\n controlProps.value = new Date(dtValue);\n }\n }\n\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Default the lookup field props will determine the default type\n controlProps.type = props.field.AllowMultipleValues ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // See if this field is readonly and a value exists\n\n if (isReadonly) {\n // Update the value\n controlProps.type = core_1.Components.FormControlTypes.Readonly; // Ensure a value exists\n\n if (props.value) {\n // Set the rendered event\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n };\n }\n } else {\n // Set the rendering event\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Display a loading message\n\n controlProps.loadingMessage = \"Loading the Lookup Data\"; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Load the field information\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n lookupFieldInfo = fieldInfo; // Set the lookup filter\n\n lookupFieldInfo.lookupFilter = controlProps.lookupFilter; // Update the multi property\n\n controlProps.multi = lookupFieldInfo.multi; // Get the drop down information\n\n gd_sprest_1.Helper.ListFormField.loadLookupData(lookupFieldInfo, 500).then( // Success\n function (items) {\n // Get the dropdown items\n var ddlItems = getLookupItems(props.field, items, props.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !lookupFieldInfo.multi) {\n // Add a blank entry\n ddlItems = [{\n text: \"\",\n value: null\n }].concat(ddlItems);\n } // Set the items\n\n\n controlProps.items = ddlItems; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Clear the value, since the getLookupItems method takes care of this for us\n\n controlProps.value = null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the lookup field values for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the field information for field '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n controlProps.el.innerHTML = \"\";\n core_1.Components.Alert({\n el: controlProps.el,\n content: \"Error loading the lookup field information.\",\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n });\n };\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var isChoice = props.field.SchemaXml.indexOf('Format=\"RadioButtons\"') > 0 ? true : false; // Set the type\n\n controlProps.type = isChoice ? core_1.Components.FormControlTypes.MultiSwitch : core_1.Components.FormControlTypes.MultiDropdown; // Update the value\n\n controlProps.value = (props.value ? props.value.results : null) || props.value; // Set the items\n\n controlProps.items = getChoiceItems(isChoice, props.field, props.value);\n break;\n // Note\n\n case gd_sprest_1.SPTypes.FieldType.Note:\n // Set the properties\n controlProps.type = core_1.Components.FormControlTypes.TextArea;\n controlProps.rows = props.field.NumberOfLines;\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField_1 = props.field;\n var numberProps = controlProps; // Set the default value\n\n numberProps.value = numberProps.value == null ? numberField_1.DefaultValue : numberProps.value; // See if this is a percentage\n\n var isPercent = numberField_1.ShowAsPercentage;\n\n if (isPercent == null) {\n // Set the value from the schema (2013 environments)\n isPercent = numberField_1.SchemaXml.toLowerCase().indexOf('percentage=\"true\"') > 0;\n }\n\n if (isPercent) {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.Range; // Default the max\n\n numberProps.max = numberField_1.MaximumValue == 1 || numberField_1.MaximumValue == Number.MAX_VALUE ? 100 : numberField_1.MaximumValue; // Set the min value\n\n numberProps.min = numberField_1.MinimumValue == -1.7976931348623157e+308 ? 0 : numberField_1.MinimumValue; // Set the value\n\n numberProps.value = numberProps.value == null || numberProps.value == Number.MIN_VALUE ? 0 : numberProps.value;\n numberProps.value = numberProps.value * (numberProps.max == 100 && numberProps.value < 1 ? 100 : 1);\n } // Else, see if the min/max values are defined\n else if (typeof numberField_1.MaximumValue == \"number\" && numberField_1.MaximumValue != Number.MAX_VALUE && typeof numberField_1.MinimumValue == \"number\" && numberField_1.MinimumValue != Number.MIN_VALUE) {\n // Update the properties to display a range\n numberProps.type = core_1.Components.FormControlTypes.Range;\n numberProps.max = numberField_1.MaximumValue;\n numberProps.min = numberField_1.MinimumValue;\n numberProps.value = typeof numberProps.value == \"number\" ? numberProps.value : numberProps.min; // Set validation\n\n if (numberField_1.MinimumValue || numberField_1.MaximumValue) {\n // Add validation\n baseValidation = function baseValidation(control, result) {\n // Ensure the value is a number\n if (/^[0-9]*$/.test(result.value) == false) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be a number.\";\n return result;\n } // Validate the min value\n\n\n if (numberField_1.MinimumValue && result.value < numberField_1.MinimumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be greater than or equal to \" + numberField_1.MinimumValue;\n return result;\n } // Validate the max value\n\n\n if (numberField_1.MaximumValue && result.value > numberField_1.MaximumValue) {\n // Update the validation and return it\n result.isValid = false;\n result.invalidMessage = \"The value must be less than or equal to \" + numberField_1.MaximumValue;\n return result;\n } // Valid\n\n\n result.isValid = true; // Return the result\n\n return result;\n };\n }\n } else {\n // Set the type\n numberProps.type = core_1.Components.FormControlTypes.TextField;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n var desc_1 = null;\n var url_1 = null;\n var value_1 = props.value; // See if a value exists\n\n if (props.value) {\n // Update the value\n controlProps.value = props.value.Url;\n } // Set the render event\n\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // Clear the element\n\n control.el.innerHTML = \"\"; // See if we are rendering the description\n\n var showDesc = controlProps.showDescription;\n showDesc = typeof showDesc === \"boolean\" ? showDesc : true;\n\n if (showDesc) {\n // Render the description\n desc_1 = core_1.Components.FormControl({\n className: \"mb-1\",\n el: control.el,\n placeholder: \"Description\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Description : null\n });\n } // Render the url\n\n\n url_1 = core_1.Components.FormControl({\n el: control.el,\n placeholder: \"Url\",\n type: core_1.Components.FormControlTypes.TextField,\n value: value_1 ? value_1.Url : null\n }); // Set the get value event\n\n control.props.onGetValue = function () {\n // Return the value\n return {\n Description: desc_1 ? desc_1.getValue() : url_1.getValue(),\n Url: url_1.getValue()\n };\n }; // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n }; // Set the validate event\n\n\n baseValidation = function baseValidation(control, result) {\n var descValid,\n urlValid = false; // Get the form control elements\n\n var elFormControl = control.el.querySelectorAll(\".form-control\"); // See if both the description and url are displayed\n\n var elDesc = null;\n var elUrl = null;\n\n if (elFormControl.length > 1) {\n // Set the elements\n elDesc = elFormControl[0];\n elUrl = elFormControl[1];\n } else {\n // Set the elements\n elUrl = elFormControl[0]; // Set the flag\n\n descValid = true;\n } // See if the description exists\n\n\n if (elDesc) {\n // Clear the classes\n elDesc.classList.remove(\"is-invalid\");\n elDesc.classList.remove(\"is-valid\"); // Set the flag\n\n descValid = control.props.required ? desc_1.getValue() ? true : false : true; // Set the class\n\n elDesc.classList.add(descValid ? \"is-valid\" : \"is-invalid\");\n } // See if the url exists\n\n\n if (elUrl) {\n // Clear the classes\n elUrl.classList.remove(\"is-invalid\");\n elUrl.classList.remove(\"is-valid\"); // Set the flag\n\n urlValid = control.props.required ? url_1.getValue() ? true : false : true; // Set the class\n\n elUrl.classList.add(urlValid ? \"is-valid\" : \"is-invalid\");\n } // Set the validation falg\n\n\n result.isValid = descValid && urlValid; // Return the result\n\n return result;\n };\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Set the type\n controlProps.type = isReadonly ? core_1.Components.FormControlTypes.Readonly : peoplePicker_1.PeoplePickerControlType; // Update the properties, based on the field settings\n\n controlProps.allowGroups = props.field.SelectionGroup == gd_sprest_1.SPTypes.FieldUserSelectionType.PeopleAndGroups;\n controlProps.groupId = props.field.SelectionGroup;\n controlProps.multi = props.field.AllowMultipleValues; // Set the rendered event\n\n onControlRendered = controlProps.onControlRendered;\n\n controlProps.onControlRendered = function (formControl) {\n // Save the control\n control = formControl; // See if this field is readonly and a value exists\n\n if (props.value && isReadonly) {\n // Set the class name\n control.el.classList.add(\"form-control\");\n control.el.style.backgroundColor = \"#e9ecef\"; // Override the html rendered\n\n control.el.innerHTML = props.listInfo.fieldValuesAsHtml[props.field.InternalName];\n } // Call the event\n\n\n onControlRendered ? onControlRendered(formControl) : null;\n };\n\n break;\n } // See if this is the document name field\n\n\n if (props.field.InternalName == \"FileLeafRef\") {\n // Set base validation\n baseValidation = function baseValidation(control, result) {\n var value = result.value; // Ensure the value exists\n\n result.isValid = value ? true : false;\n\n if (result.isValid) {\n // See if it ends w/ a .\n if (value[value.length - 1] == '.') {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot end with a '.' character.\";\n } // Else, see if it contains invalid characters\n else if (/[~\"\\#\\%\\&\\*\\:\\<\\>\\?\\/\\\\\\{\\|\\}\"]/.test(value) || value.indexOf('\\\\') >= 0) {\n // Update the validation\n result.isValid = false;\n result.invalidMessage = \"The value cannot contain the following characters: ~ \\\" # % & * : < > ? / \\\\ { | }\";\n } // Else, see if we are changing the extension\n else if (control.props.value) {\n // Get the file extensions\n var origExtension = getFileExtension(control.props.value);\n var newExtension = getFileExtension(value); // Update the validation\n\n result.isValid = origExtension == newExtension;\n result.invalidMessage = \"The file extension cannot be changed. It must end with '.\" + origExtension + \"'\";\n }\n } // Return the validation result\n\n\n return result;\n };\n } // See if this is a taxonomy field\n\n\n if (/^TaxonomyFieldType/.test(props.field.TypeAsString)) {\n // Set the type\n controlProps.type = core_1.Components.FormControlTypes.Dropdown; // Set a render event\n\n onControlRendering = controlProps.onControlRendering;\n\n controlProps.onControlRendering = function (newProps) {\n // Update the control properties\n controlProps = newProps; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Display a loading message\n controlProps.loadingMessage = \"Loading the MMS Data\"; // Load the field information\n\n gd_sprest_1.Helper.ListFormField.create({\n field: props.field,\n listName: props.listInfo.list.Title,\n name: props.field.InternalName,\n webUrl: props.listInfo.webUrl\n }).then( // Success\n function (fieldInfo) {\n // Save the field information\n mmsFieldInfo = fieldInfo; // Set the type\n\n controlProps.type = mmsFieldInfo.multi ? core_1.Components.FormControlTypes.MultiDropdown : core_1.Components.FormControlTypes.Dropdown; // Load the value field\n\n gd_sprest_1.Helper.ListFormField.loadMMSValueField(mmsFieldInfo).then( // Success\n function (valueField) {\n // Set the value field\n mmsFieldInfo.valueField = valueField; // See if this is a new form\n\n if (props.controlMode == gd_sprest_1.SPTypes.ControlMode.New) {\n var fieldValue = []; // Get the default values\n\n var values = (props.field.DefaultValue || \"\").split(\";#\");\n\n for (var i = 0; i < values.length; i++) {\n var value = values[i].split(\"|\");\n\n if (value.length == 2) {\n // Add the term id\n fieldValue.push(value[1]);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } else {\n var fieldValue = props.value; // Get the field value\n\n var values = fieldValue && fieldValue.results ? fieldValue.results : [fieldValue]; // Clear the field values\n\n fieldValue = []; // Parse the values\n\n for (var i = 0; i < values.length; i++) {\n // Ensure the value exists\n if (values[i] && values[i].TermGuid) {\n // Add the value\n fieldValue.push(values[i].TermGuid);\n }\n } // Update the field value\n\n\n controlProps.value = fieldValue;\n } // Load the terms\n\n\n gd_sprest_1.Helper.ListFormField.loadMMSData(mmsFieldInfo).then( // Success\n function (terms) {\n // Get the items\n var items = getMMSItems(gd_sprest_1.Helper.Taxonomy.toObject(terms), controlProps.value); // See if this is not a required field and not a multi-select\n\n if (!isRequired && !mmsFieldInfo.multi) {\n // Add a blank entry\n items = [{\n text: \"\",\n value: null\n }].concat(items);\n } // Set the items\n\n\n controlProps.items = items; // Clear the element\n\n controlProps.el ? controlProps.el.innerHTML = \"\" : null; // Call the event\n\n var returnVal = onControlRendering ? onControlRendering(controlProps) : null;\n\n if (returnVal && returnVal.then) {\n // Wait for the promise to complete\n returnVal.then(function (props) {\n // Resolve the promise\n resolve(props || controlProps);\n });\n } else {\n // Resolve the promise\n resolve(controlProps);\n }\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms terms for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null;\n });\n }, // Error\n function (msg) {\n // Set the error message\n var errorMessage = \"Error loading the mms value field for '\" + props.field.InternalName + \"'.\"; // Display an error message\n\n core_1.Components.Alert({\n el: controlProps.el,\n content: errorMessage,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(errorMessage) : null; // Reject the request\n\n reject(msg);\n });\n }, function (msg) {\n // Display an error message\n core_1.Components.Alert({\n el: controlProps.el,\n content: msg,\n type: core_1.Components.AlertTypes.Danger\n }); // Call the error event\n\n props.onError ? props.onError(msg) : null;\n });\n });\n };\n } // Create the field\n\n\n var field = {\n control: control,\n controlProps: controlProps,\n getValue: function getValue() {\n var fieldValue = {\n name: props.field.InternalName,\n value: control ? control.getValue() : null\n }; // Update the field name/value, based on the type\n\n switch (props.field.FieldTypeKind) {\n // Boolean\n case gd_sprest_1.SPTypes.FieldType.Boolean:\n // Update the value\n fieldValue.value = fieldValue.value ? true : false;\n break;\n // Choice\n\n case gd_sprest_1.SPTypes.FieldType.Choice:\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.Dropdown) {\n // See if there is a value\n var ddlValue = fieldValue.value;\n\n if (ddlValue) {\n // Update the field value\n fieldValue.value = ddlValue.value || ddlValue.text;\n }\n } else {\n // See if there is a value\n var cbValue = fieldValue.value;\n\n if (cbValue) {\n // Update the field value\n fieldValue.value = cbValue.label;\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Currency:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value || null;\n break;\n // Date/Time\n\n case gd_sprest_1.SPTypes.FieldType.DateTime:\n // Ensure a value exists, otherwise null\n fieldValue.value = fieldValue.value ? fieldValue.value.toISOString() : null;\n break;\n // Lookup\n\n case gd_sprest_1.SPTypes.FieldType.Lookup:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (lookupFieldInfo.multi) {\n var values_1 = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values_1.length; j++) {\n // Add the value\n fieldValue.value.results.push(values_1[j].value || values_1[j].text);\n }\n } else {\n // Update the field value\n fieldValue.value = fieldValue.value ? fieldValue.value.value || fieldValue.value.text : null; // Ensure a value exists, otherwise null\n\n fieldValue.value = fieldValue.value || null;\n }\n\n break;\n // Multi-Choice\n\n case gd_sprest_1.SPTypes.FieldType.MultiChoice:\n var values = fieldValue.value || [];\n fieldValue.value = {\n results: []\n }; // Parse the values\n\n for (var j = 0; j < values.length; j++) {\n // See if this is a dropdown\n if (controlProps.type == core_1.Components.FormControlTypes.MultiDropdown) {\n // See if there is a value\n var ddlValue = values[j]; // Add the values\n\n fieldValue.value.results.push(ddlValue.value || ddlValue.text);\n } else {\n // See if there is a value\n var cbValue = values[j]; // Add the values\n\n fieldValue.value.results.push(cbValue.label);\n }\n }\n\n break;\n // Number Field\n\n case gd_sprest_1.SPTypes.FieldType.Number:\n var numberField = props.field; // Ensure a field value exists\n\n if (fieldValue.value) {\n // See if this is a percentage\n if (numberField.ShowAsPercentage) {\n // Update the value\n fieldValue.value = fieldValue.value / 100;\n }\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // URL\n\n case gd_sprest_1.SPTypes.FieldType.URL:\n // See if the field value exists\n if (fieldValue.value && fieldValue.value.Url) {\n // Set the url, and validate the format\n var url = fieldValue.value.Url;\n\n if (url && /^http/.test(url.toLowerCase()) == false) {\n // Update the url, otherwise the request will fail\n url = \"https://\" + url;\n } // Add the metadata\n\n\n fieldValue.value = {\n __metadata: {\n type: \"SP.FieldUrlValue\"\n },\n Description: fieldValue.value.Description || \"\",\n Url: url\n };\n } else {\n // Ensure the value is null\n fieldValue.value = null;\n }\n\n break;\n // User\n\n case gd_sprest_1.SPTypes.FieldType.User:\n // Append 'Id' to the field name\n fieldValue.name += fieldValue.name.lastIndexOf(\"Id\") == fieldValue.name.length - 2 ? \"\" : \"Id\"; // See if this is a multi-value field\n\n if (props.field.AllowMultipleValues) {\n var values_2 = fieldValue.value || []; // Default the value\n\n fieldValue.value = {\n results: []\n }; // Parse the options\n\n for (var j = 0; j < values_2.length; j++) {\n var userValue = values_2[j]; // Add the field value\n\n userValue.Id ? fieldValue.value.results.push(userValue.Id) : null;\n }\n } else {\n var userValue = fieldValue.value ? fieldValue.value[0] : null; // Set the field value\n\n fieldValue.value = userValue && userValue.Id ? userValue.Id : null;\n }\n\n break;\n // MMS\n\n default:\n // See if this is a MMS field\n if (mmsFieldInfo) {\n // Update the field name to the value field\n fieldValue.name = mmsFieldInfo ? mmsFieldInfo.valueField.InternalName : fieldValue.name + \"_0\"; // See if this is a multi field\n\n if (mmsFieldInfo.multi) {\n // Parse the field values\n var fieldValues = fieldValue.value || [];\n fieldValue.value = [];\n\n for (var j = 0; j < fieldValues.length; j++) {\n var termInfo = fieldValues[j]; // Add the field value\n\n fieldValue.value.push(-1 + \";#\" + termInfo.text + \"|\" + termInfo.value);\n } // Set the field value\n\n\n fieldValue.value = fieldValue.value.join(\";#\");\n } else {\n // Set the value\n fieldValue.value = fieldValue.value && fieldValue.value.value ? -1 + \";#\" + fieldValue.value.text + \"|\" + fieldValue.value.value : \"\";\n }\n }\n\n break;\n } // Return the field value\n\n\n return fieldValue;\n },\n isValid: function isValid() {\n // See if there is base validation\n if (baseValidation) {\n // Validate the field\n var baseResult = baseValidation(control, {\n isValid: false,\n value: control.getValue()\n }); // Validate the current control\n\n var result = controlProps.onValidate ? controlProps.onValidate(controlProps, baseResult) : baseResult; // Return the flag\n\n if (typeof result === \"boolean\") {\n // Update the validation\n baseResult.isValid = result;\n control.updateValidation(control.el, baseResult); // Return the result\n\n return result;\n } // Update the validation\n\n\n control.updateValidation(control.el, result); // Return the flag\n\n return result.isValid;\n } // Validate the control\n\n\n return control ? control.isValid : false;\n }\n }; // Execute the assign to event\n\n props.assignTo ? props.assignTo(field) : null; // Return the field\n\n return field;\n};\n\nexports.Field = Field;\n\n//# sourceURL=webpack://gd-sprest-bs/./build/components/field/index.js?");
669
669
 
670
670
  /***/ }),
671
671