gd-sprest-react
Advanced tools
Comparing version 2.5.1 to 2.5.2
/// <reference types="react" /> | ||
import { IBaseFieldInfo, IBaseFieldProps } from "../definitions"; | ||
import { Types } from "gd-sprest"; | ||
import { IBaseFieldProps } from "../definitions"; | ||
import { Fields } from ".."; | ||
@@ -18,3 +19,3 @@ /** | ||
*/ | ||
readonly Info: IBaseFieldInfo; | ||
readonly Info: Types.Helper.ListForm.IListFormFieldInfo; | ||
/** | ||
@@ -21,0 +22,0 @@ * Get the field value |
@@ -44,10 +44,2 @@ "use strict"; | ||
var fieldInfo = _this.state.fieldInfo; | ||
// See if this is a user or lookup field | ||
if (fieldInfo.type == gd_sprest_1.SPTypes.FieldType.Lookup || fieldInfo.type == gd_sprest_1.SPTypes.FieldType.User) { | ||
// Ensure the default value is set | ||
if (_this.props.defaultValue == null && _this.props.item) { | ||
// Update the default value | ||
defaultValue = _this.props.item[fieldInfo.name + "Id"]; | ||
} | ||
} | ||
// Return the field component, based on the type | ||
@@ -54,0 +46,0 @@ switch (fieldInfo.type) { |
@@ -99,6 +99,12 @@ "use strict"; | ||
}); | ||
// Set the default value | ||
var defaultValue = item[field.InternalName]; | ||
if (defaultValue == null && (field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Lookup || field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.User)) { | ||
// Try to set it to the "Id" field value | ||
defaultValue = item[field.InternalName + "Id"]; | ||
} | ||
// Add the form field | ||
formFields.push(React.createElement("div", { className: "ms-Grid-row", key: "row_" + fieldName }, | ||
React.createElement("div", { className: "ms-Grid-col ms-md12" }, | ||
React.createElement(_1.Field, { controlMode: readOnly ? gd_sprest_1.SPTypes.ControlMode.Display : _this.ControlMode, defaultValue: item[field.InternalName], field: field, item: item, listName: _this.props.listName, key: field.InternalName, name: field.InternalName, onChange: fieldInfo ? fieldInfo.onChange : null, onFieldRender: _this.props.onFieldRender, onRender: fieldInfo ? fieldInfo.onRender : null, queryTop: _this.props.queryTop, ref: function (field) { field ? _this._formFields[field.props.name] = field : null; }, webUrl: _this.props.webUrl })))); | ||
React.createElement(_1.Field, { className: _this.props.fieldClassName, controlMode: readOnly ? gd_sprest_1.SPTypes.ControlMode.Display : _this.ControlMode, defaultValue: defaultValue, field: field, listName: _this.props.listName, key: field.InternalName, name: field.InternalName, onChange: fieldInfo ? fieldInfo.onChange : null, onFieldRender: _this.props.onFieldRender, onRender: fieldInfo ? fieldInfo.onRender : null, queryTop: _this.props.queryTop, ref: function (field) { field ? _this._formFields[field.props.name] = field : null; }, webUrl: _this.props.webUrl })))); | ||
}; | ||
@@ -233,9 +239,10 @@ // Parse the form fields | ||
var field = this._formFields[fieldName]; | ||
// Ensure the field exists | ||
if (field == null) { | ||
var fieldInfo = field ? field.state.fieldInfo : null; | ||
// Ensure the field information exists | ||
if (fieldInfo == null) { | ||
continue; | ||
} | ||
// See if this is a lookup or user field | ||
if (field.Info.type == gd_sprest_1.SPTypes.FieldType.Lookup || | ||
field.Info.type == gd_sprest_1.SPTypes.FieldType.User) { | ||
if (fieldInfo.type == gd_sprest_1.SPTypes.FieldType.Lookup || | ||
fieldInfo.type == gd_sprest_1.SPTypes.FieldType.User) { | ||
// Ensure the field name is the "Id" field | ||
@@ -254,3 +261,3 @@ fieldName += fieldName.lastIndexOf("Id") == fieldName.length - 2 ? "" : "Id"; | ||
// See if this is a taxonomy field with multiple values | ||
if (field.Info.typeAsString == "TaxonomyFieldTypeMulti") { | ||
if (fieldInfo.typeAsString == "TaxonomyFieldTypeMulti") { | ||
// Add the term | ||
@@ -265,5 +272,9 @@ results.push(result.WssId + ";#" + result.Label + "|" + result.TermGuid); | ||
// See if this is a taxonomy field with multiple values | ||
if (field.Info.typeAsString == "TaxonomyFieldTypeMulti") { | ||
if (fieldInfo.typeAsString == "TaxonomyFieldTypeMulti") { | ||
// Set the hidden field name | ||
formValues[field.Info.valueField] = results.join(";#"); | ||
var valueField = field.state.valueField; | ||
if (valueField) { | ||
// Update the value field | ||
formValues[valueField.InternalName] = results.join(";#"); | ||
} | ||
// Continue the loop | ||
@@ -277,4 +288,4 @@ continue; | ||
} | ||
else if (field.Info.type == gd_sprest_1.SPTypes.FieldType.Lookup || | ||
field.Info.type == gd_sprest_1.SPTypes.FieldType.User) { | ||
else if (fieldInfo.type == gd_sprest_1.SPTypes.FieldType.Lookup || | ||
fieldInfo.type == gd_sprest_1.SPTypes.FieldType.User) { | ||
// Clear the value if it doesn't exist | ||
@@ -284,6 +295,2 @@ fieldValue = fieldValue > 0 ? fieldValue : null; | ||
} | ||
else if (field.Info.type == gd_sprest_1.SPTypes.FieldType.MultiChoice) { | ||
// Default the value | ||
fieldValue = { results: [] }; | ||
} | ||
// Set the field value | ||
@@ -290,0 +297,0 @@ formValues[fieldName] = fieldValue; |
/// <reference types="react" /> | ||
import { Types } from "gd-sprest"; | ||
/** | ||
* Base Field Information | ||
*/ | ||
export interface IBaseFieldInfo { | ||
/** The default value. */ | ||
defaultValue?: any; | ||
/** The error message to display. This requires the "required" property to be set to true. */ | ||
errorMessage?: string; | ||
/** The list item. */ | ||
item?: object; | ||
/** The list name. */ | ||
listName: string; | ||
/** The internal name of the field. */ | ||
name: string; | ||
/** Flag indicating if the field is read-only. */ | ||
readOnly?: boolean; | ||
/** True indicates a required field type. */ | ||
required?: boolean; | ||
/** The display name of the field. */ | ||
title?: string; | ||
/** The field type. */ | ||
type?: number; | ||
/** The field type as a string. */ | ||
typeAsString?: string; | ||
/** The relative web url containing the list. */ | ||
webUrl?: string; | ||
} | ||
/** | ||
* Base Field Properties | ||
*/ | ||
export interface IBaseFieldProps extends IBaseFieldInfo { | ||
export interface IBaseFieldProps { | ||
/** The class name. */ | ||
@@ -38,10 +11,18 @@ className?: string; | ||
controlMode?: number; | ||
/** The list field. */ | ||
field?: Types.IFieldResult | Types.IFieldQueryResult; | ||
/** The field information. */ | ||
fieldInfo?: Types.Helper.ListForm.IListFormFieldInfo; | ||
/** The default field value. */ | ||
defaultValue?: any; | ||
/** The field. */ | ||
field: Types.IFieldResult | Types.IFieldQueryResult; | ||
/** The list name containing the field. */ | ||
listName: string; | ||
/** The field name. */ | ||
name: string; | ||
/** The on change event */ | ||
onChange?: (value: any) => void; | ||
/** The field render event. */ | ||
onFieldRender?: (fieldInfo: IBaseFieldInfo, field: JSX.Element) => any; | ||
onFieldRender?: (fieldInfo: Types.Helper.ListForm.IListFormFieldInfo, field: JSX.Element) => any; | ||
/** The render event of the field component */ | ||
onRender?: (fieldInfo: IBaseFieldInfo) => any; | ||
onRender?: (fieldInfo: Types.Helper.ListForm.IListFormFieldInfo) => any; | ||
/** The max number of items to return for the lookup data queries. (Default: 500) */ | ||
@@ -51,2 +32,4 @@ queryTop?: number; | ||
showLoadingFl?: boolean; | ||
/** The relative url of the web containing the field. */ | ||
webUrl?: string; | ||
} | ||
@@ -59,8 +42,8 @@ /** | ||
controlMode?: number; | ||
/** The error message. */ | ||
errorMessage?: string; | ||
/** The field information. */ | ||
fieldInfo: IBaseFieldInfo; | ||
fieldInfo: Types.Helper.ListForm.IListFormFieldInfo; | ||
/** Flag to determine if the field is initialized. */ | ||
initFl?: boolean; | ||
/** The field label. */ | ||
label?: string; | ||
/** The change event */ | ||
@@ -83,9 +66,5 @@ onChange?: (value: any) => void; | ||
/** | ||
* Event triggered after the field information is retrieved from SharePoint. | ||
*/ | ||
onFieldInit?: (field: Types.IField, state: IBaseFieldState) => void; | ||
/** | ||
* Event triggered after loading the field information. | ||
*/ | ||
onFieldLoaded?: () => void; | ||
onFieldLoaded?: (info: any, state: IBaseFieldState) => void; | ||
/** | ||
@@ -92,0 +71,0 @@ * Method to update the value |
import { Types } from "gd-sprest"; | ||
import { IDropdownOption, IDropdownProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
* Choice Field Information | ||
*/ | ||
export interface IChoiceFieldInfo extends IBaseFieldInfo { | ||
/** The dropdown choices. */ | ||
choices: Types.ComplexTypes.FieldMultiChoiceValue; | ||
/** Flag to determine if this is a multi-choice field. */ | ||
multiChoice?: boolean; | ||
} | ||
/** | ||
* Choice Field Properties | ||
@@ -27,3 +18,3 @@ */ | ||
/** The field information */ | ||
fieldInfo: IChoiceFieldInfo; | ||
fieldInfo: Types.Helper.ListForm.IListFormChoiceFieldInfo; | ||
/** The dropdown options. */ | ||
@@ -39,3 +30,3 @@ options?: Array<IDropdownOption>; | ||
*/ | ||
onFieldInit: (field: Types.IFieldChoice | Types.IFieldMultiChoice, state: IBaseFieldState) => void; | ||
onFieldLoaded: (fieldInfo: Types.Helper.ListForm.IListFormChoiceFieldInfo, state: IFieldChoiceState) => void; | ||
} |
import { Types } from "gd-sprest"; | ||
import { IDatePickerProps, IDropdownProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
* Date/Time Field Information | ||
*/ | ||
export interface IDateTimeFieldInfo extends IBaseFieldInfo { | ||
showTime?: boolean; | ||
} | ||
/** | ||
* Date/Time Field Properties | ||
@@ -25,3 +19,4 @@ */ | ||
export interface IFieldDateTimeState extends IBaseFieldState { | ||
fieldInfo: IDateTimeFieldInfo; | ||
/** The field information */ | ||
fieldInfo: Types.Helper.ListForm.IListFormDateFieldInfo; | ||
} | ||
@@ -35,3 +30,3 @@ /** | ||
*/ | ||
onFieldInit: (field: Types.IFieldDateTime, state: IBaseFieldState) => void; | ||
onFieldLoaded?: (info: any, state: IBaseFieldState) => void; | ||
} |
import { Types } from "gd-sprest"; | ||
import { IDropdownOption, IDropdownProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
* Lookup Field Information | ||
*/ | ||
export interface ILookupFieldInfo extends IBaseFieldInfo { | ||
/** Flag to allow multiple items to be selected. */ | ||
allowMultipleValues: boolean; | ||
/** The lookup items. */ | ||
items: Array<Types.IListItemQueryResult>; | ||
/** The lookup field name. */ | ||
lookupFieldName: string; | ||
/** The lookup list name. */ | ||
lookupListName: string; | ||
/** The lookup web id. */ | ||
lookupWebId: string; | ||
} | ||
/** | ||
* Lookup Field Properties | ||
@@ -33,3 +18,3 @@ */ | ||
/** The field information */ | ||
fieldInfo: ILookupFieldInfo; | ||
fieldInfo: Types.Helper.ListForm.IListFormLookupFieldInfo; | ||
/** The dropdown options. */ | ||
@@ -45,3 +30,3 @@ options?: Array<IDropdownOption>; | ||
*/ | ||
onFieldInit: (field: Types.IFieldLookup, state: IBaseFieldState) => void; | ||
onFieldLoaded?: (info: any, state: IBaseFieldState) => void; | ||
} |
import { Types } from "gd-sprest"; | ||
import { IDropdownOption, IDropdownProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
@@ -13,17 +13,2 @@ * Managed Metadata Term Information | ||
/** | ||
* Managed Metadata Field Information | ||
*/ | ||
export interface IManagedMetadataFieldInfo extends IBaseFieldInfo { | ||
/** Flag to allow multiple items to be selected. */ | ||
allowMultipleValues: boolean; | ||
/** The terms. */ | ||
terms: Array<IManagedMetadataTermInfo>; | ||
/** The term set id. */ | ||
termSetId: string; | ||
/** The term store id. */ | ||
termStoreId: string; | ||
/** The value field. */ | ||
valueField?: string; | ||
} | ||
/** | ||
* Lookup Field Properties | ||
@@ -42,5 +27,7 @@ */ | ||
/** The field information */ | ||
fieldInfo: IManagedMetadataFieldInfo; | ||
fieldInfo: Types.Helper.ListForm.IListFormMMSFieldInfo; | ||
/** The dropdown options. */ | ||
options?: Array<IDropdownOption>; | ||
/** The hidden value field. */ | ||
valueField?: Types.IFieldManagedMetadata; | ||
} | ||
@@ -54,3 +41,3 @@ /** | ||
*/ | ||
onFieldInit: (field: Types.IFieldManagedMetadata, state: IFieldManagedMetadataState) => void; | ||
onFieldLoaded?: (info: any, state: IBaseFieldState) => void; | ||
} |
import { Types } from "gd-sprest"; | ||
import { ITextFieldProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
@@ -13,13 +13,2 @@ * Number Field Types | ||
/** | ||
* Number Field Information | ||
*/ | ||
export interface INumberFieldInfo extends IBaseFieldInfo { | ||
/** The maximum value. */ | ||
maxValue?: number; | ||
/** The minimum value. */ | ||
minValue?: number; | ||
/** Flag to determine if the value is a percentage. */ | ||
showAsPercentage?: boolean; | ||
} | ||
/** | ||
* Number Field Properties | ||
@@ -40,3 +29,3 @@ */ | ||
/** The field information. */ | ||
fieldInfo: INumberFieldInfo; | ||
fieldInfo: Types.Helper.ListForm.IListFormNumberFieldInfo; | ||
} | ||
@@ -50,3 +39,3 @@ /** | ||
*/ | ||
onFieldInit: (field: Types.IFieldCurrency | Types.IFieldNumber, state: IBaseFieldState) => void; | ||
onFieldLoaded?: (info: any, state: IBaseFieldState) => void; | ||
} |
import { Types } from "gd-sprest"; | ||
import { ITextFieldProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
* Text Field Information | ||
*/ | ||
export interface ITextFieldInformation extends IBaseFieldInfo { | ||
multiline?: boolean; | ||
richText?: boolean; | ||
rows?: number; | ||
} | ||
/** | ||
* Text Field Properties | ||
@@ -25,3 +17,4 @@ */ | ||
export interface IFieldTextState extends IBaseFieldState { | ||
fieldInfo: ITextFieldInformation; | ||
/** The field information */ | ||
fieldInfo: Types.Helper.ListForm.IListFormTextFieldInfo; | ||
} | ||
@@ -35,3 +28,3 @@ /** | ||
*/ | ||
onFieldInit: (field: Types.IFieldNote | Types.IFieldText, state: IBaseFieldState) => void; | ||
onFieldLoaded?: (info: any, state: IBaseFieldState) => void; | ||
} |
import { Types } from "gd-sprest"; | ||
import { ITextFieldProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
* Url Field Information | ||
*/ | ||
export interface IUrlFieldInformation extends IBaseFieldInfo { | ||
multiline?: boolean; | ||
rows?: number; | ||
} | ||
/** | ||
* Url Field Properties | ||
@@ -26,3 +19,3 @@ */ | ||
export interface IFieldUrlState extends IBaseFieldState { | ||
fieldInfo: IUrlFieldInformation; | ||
/** The field value */ | ||
value: Types.ComplexTypes.FieldUrlValue; | ||
@@ -34,6 +27,2 @@ } | ||
export interface IFieldUrl extends IBaseField<IFieldUrlProps, IFieldUrlState> { | ||
/** | ||
* Event triggered after the field information is retrieved from SharePoint. | ||
*/ | ||
onFieldInit: (field: Types.IFieldUrl, state: IBaseFieldState) => void; | ||
} |
import { Types } from "gd-sprest"; | ||
import { ILabelProps, IPeoplePickerProps } from "office-ui-fabric-react"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState, IBaseFieldInfo } from "../definitions"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
/** | ||
* User Field Information | ||
*/ | ||
export interface IUserFieldInfo extends IBaseFieldInfo { | ||
allowGroups?: boolean; | ||
allowMultiple?: boolean; | ||
} | ||
/** | ||
* User Field Properties | ||
@@ -26,3 +19,4 @@ */ | ||
export interface IFieldUserState extends IBaseFieldState { | ||
fieldInfo: IUserFieldInfo; | ||
/** The field information */ | ||
fieldInfo: Types.Helper.ListForm.IListFormUserFieldInfo; | ||
} | ||
@@ -36,3 +30,3 @@ /** | ||
*/ | ||
onFieldInit: (field: Types.IFieldUser, state: IBaseFieldState) => void; | ||
onFieldLoaded?: (info: any, state: IBaseFieldState) => void; | ||
} |
/// <reference types="react" /> | ||
import { Types } from "gd-sprest"; | ||
import { IAttachmentFile, IBaseFieldInfo } from "."; | ||
import { IAttachmentFile } from "."; | ||
/** | ||
@@ -15,3 +15,3 @@ * Field Information | ||
/** The on render method */ | ||
onRender?: (fieldInfo: IBaseFieldInfo) => JSX.Element; | ||
onRender?: (fieldInfo: Types.Helper.ListForm.IListFormFieldInfo) => JSX.Element; | ||
} | ||
@@ -30,2 +30,4 @@ /** | ||
excludeFields?: Array<string>; | ||
/** The field class name to apply to the field elements. */ | ||
fieldClassName?: string; | ||
/** The form fields. */ | ||
@@ -46,3 +48,3 @@ fields?: Array<IItemFormField>; | ||
/** The field render event */ | ||
onFieldRender?: (fieldInfo: IBaseFieldInfo, field: JSX.Element) => any; | ||
onFieldRender?: (fieldInfo: Types.Helper.ListForm.IListFormFieldInfo, field: JSX.Element) => any; | ||
/** The on form render event. */ | ||
@@ -49,0 +51,0 @@ onRender?: (controlMode: number) => any; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { Types } from "gd-sprest"; | ||
import { IBaseField, IBaseFieldProps, IBaseFieldState } from "../definitions"; | ||
@@ -15,6 +16,9 @@ /** | ||
/** | ||
* Component initialized event | ||
* Method to render the component | ||
*/ | ||
componentWillMount(): void; | ||
render(): any; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to get the field value | ||
@@ -24,9 +28,9 @@ */ | ||
/** | ||
* Event triggered after the field information is retrieved from SharePoint | ||
* Event triggered after loading the field information | ||
*/ | ||
onFieldInit?: (field: any, state: State) => void; | ||
onFieldLoaded?: (info: Types.Helper.ListForm.IListFormFieldInfo, state: State) => void; | ||
/** | ||
* Event triggered after loading the field information | ||
* Method to render the field | ||
*/ | ||
onFieldLoaded?: () => void; | ||
renderField: () => JSX.Element; | ||
/** | ||
@@ -37,18 +41,2 @@ * Method to update the value | ||
updateValue: (value: any) => void; | ||
/** | ||
* Method to render the component | ||
*/ | ||
render(): any; | ||
/** | ||
* Method to render the field | ||
*/ | ||
renderField: () => JSX.Element; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to load the field information | ||
*/ | ||
private load; | ||
private loadField; | ||
} |
@@ -29,2 +29,5 @@ "use strict"; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to get the field value | ||
@@ -34,15 +37,2 @@ */ | ||
/** | ||
* Method to update the value | ||
* @param value - The field value. | ||
*/ | ||
_this.updateValue = function (value) { | ||
// Ensure a custom renderer doesn't exist, and call the on change event | ||
_this.props.onRender == null && _this.props.onChange ? _this.props.onChange(value) : null; | ||
// Update the state | ||
_this.setState({ | ||
showErrorMessage: _this.state.fieldInfo.required ? (value ? false : true) : false, | ||
value: value | ||
}); | ||
}; | ||
/** | ||
* Method to render the field | ||
@@ -60,63 +50,18 @@ */ | ||
/** | ||
* Methods | ||
* Method to update the value | ||
* @param value - The field value. | ||
*/ | ||
/** | ||
* Method to load the field information | ||
*/ | ||
_this.load = function () { | ||
var state = Object.create(_this.state); | ||
// See if the field exists | ||
if (_this.props.field) { | ||
// Load the field | ||
_this.loadField(state, _this.props.field); | ||
// Update the state | ||
_this.setState(state, function () { | ||
// Call the field loaded event | ||
_this.onFieldLoaded ? _this.onFieldLoaded() : null; | ||
}); | ||
} | ||
else { | ||
// Get the web | ||
(new gd_sprest_1.Web(state.fieldInfo.webUrl)) | ||
.Lists(state.fieldInfo.listName) | ||
.Fields() | ||
.getByInternalNameOrTitle(state.fieldInfo.name) | ||
.execute(function (field) { | ||
// Load the field | ||
_this.loadField(state, field); | ||
// Update the state | ||
_this.setState(state, function () { | ||
// Call the on loaded event | ||
_this.onFieldLoaded ? _this.onFieldLoaded() : null; | ||
}); | ||
}); | ||
} | ||
_this.updateValue = function (value) { | ||
// Ensure a custom renderer doesn't exist, and call the on change event | ||
_this.props.onRender == null && _this.props.onChange ? _this.props.onChange(value) : null; | ||
// Update the state | ||
_this.setState({ | ||
showErrorMessage: _this.state.fieldInfo.required ? (value ? false : true) : false, | ||
value: value | ||
}); | ||
}; | ||
// Method to load the field | ||
_this.loadField = function (state, field) { | ||
// Update the field information | ||
state.fieldInfo.defaultValue = field.DefaultValue; | ||
state.fieldInfo.readOnly = field.ReadOnlyField; | ||
state.fieldInfo.required = field.Required ? true : false; | ||
state.fieldInfo.title = field.Title; | ||
state.fieldInfo.type = field.FieldTypeKind; | ||
state.fieldInfo.typeAsString = field.TypeAsString; | ||
state.initFl = true; | ||
state.label = (state.fieldInfo.title || state.fieldInfo.name) + ":"; | ||
state.showErrorMessage = state.fieldInfo.required ? (state.fieldInfo.defaultValue ? false : true) : false; | ||
// Call the initialize event | ||
_this.onFieldInit ? _this.onFieldInit(field, state) : null; | ||
}; | ||
// Set the state | ||
_this.state = { | ||
controlMode: _this.props.controlMode, | ||
fieldInfo: { | ||
defaultValue: "", | ||
errorMessage: _this.props.errorMessage || "This field requires a value.", | ||
listName: _this.props.listName, | ||
name: _this.props.name, | ||
required: _this.props.required ? true : false, | ||
title: _this.props.title, | ||
webUrl: _this.props.webUrl | ||
}, | ||
fieldInfo: null, | ||
initFl: false, | ||
@@ -129,14 +74,8 @@ showErrorMessage: false, | ||
/** | ||
* Component initialized event | ||
*/ | ||
BaseField.prototype.componentWillMount = function () { | ||
// Load the data | ||
this.load(); | ||
}; | ||
/** | ||
* Method to render the component | ||
*/ | ||
BaseField.prototype.render = function () { | ||
// See if the field is initialized | ||
if (this.state.initFl) { | ||
var _this = this; | ||
// See if the field exists | ||
if (this.state.fieldInfo && this.state.fieldInfo.field) { | ||
var elField = null; | ||
@@ -157,2 +96,13 @@ // See if there is a custom render event | ||
} | ||
// Load the field | ||
(new gd_sprest_1.Helper.ListFormField({ | ||
field: this.props.field, | ||
listName: this.props.listName, | ||
name: this.props.name | ||
})).then(function (fieldInfo) { | ||
// Call the field loaded event | ||
_this.onFieldLoaded ? _this.onFieldLoaded(fieldInfo, _this.state) : null; | ||
// Update the state | ||
_this.setState({ fieldInfo: fieldInfo }); | ||
}); | ||
// Determine if we are showing a spinner | ||
@@ -159,0 +109,0 @@ var showFl = typeof (this.props.showLoadingFl) === "boolean" ? this.props.showLoadingFl : true; |
@@ -12,2 +12,5 @@ import { IFieldBoolean, IFieldBooleanProps, IFieldBooleanState } from "../definitions"; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to get the value | ||
@@ -14,0 +17,0 @@ */ |
@@ -48,3 +48,3 @@ "use strict"; | ||
return (React.createElement("div", { className: (_this.props.className || "") }, | ||
React.createElement(office_ui_fabric_react_1.Label, null, props.label || _this.state.label), | ||
React.createElement(office_ui_fabric_react_1.Label, null, props.label || _this.state.fieldInfo.title), | ||
React.createElement("div", null, _this.getValue() ? "Yes" : "No"))); | ||
@@ -54,6 +54,9 @@ } | ||
return (React.createElement("div", { className: (_this.props.className || "") }, | ||
React.createElement(office_ui_fabric_react_1.Label, null, props.label || _this.state.label), | ||
React.createElement(office_ui_fabric_react_1.Label, null, props.label || _this.state.fieldInfo.title), | ||
React.createElement(office_ui_fabric_react_1.Checkbox, __assign({}, props)))); | ||
}; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to get the value | ||
@@ -60,0 +63,0 @@ */ |
@@ -13,3 +13,3 @@ import { IDropdownOption } from "office-ui-fabric-react"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -23,11 +23,8 @@ /** | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* The field loaded | ||
* @param field - The field information. | ||
* @param state - The current state. | ||
*/ | ||
onFieldInit: (field: any, state: IFieldChoiceState) => void; | ||
onFieldLoaded: (info: any, state: IFieldChoiceState) => void; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to convert the field value to options | ||
@@ -34,0 +31,0 @@ */ |
@@ -44,10 +44,10 @@ "use strict"; | ||
props.disabled = _this.state.fieldInfo.readOnly || _this.props.controlMode == gd_sprest_1.SPTypes.ControlMode.Display; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.fieldInfo.errorMessage; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.errorMessage; | ||
props.errorMessage = _this.state.showErrorMessage ? (props.selectedKey ? "" : props.errorMessage) : ""; | ||
props.label = props.label || _this.state.label; | ||
props.multiSelect = _this.state.fieldInfo.multiChoice; | ||
props.label = props.label || _this.state.fieldInfo.title; | ||
props.multiSelect = _this.state.fieldInfo.multi; | ||
props.onChanged = _this.onChanged; | ||
props.options = _this.state.options; | ||
props.required = props.required || _this.state.fieldInfo.required; | ||
// See if this is a multi-choice | ||
// See if we are allowing multiple values | ||
if (props.multiSelect) { | ||
@@ -65,3 +65,3 @@ // Set the selected keys | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -75,3 +75,3 @@ /** | ||
// See if this is a multi-choice field | ||
if (_this.state.fieldInfo.multiChoice) { | ||
if (_this.state.fieldInfo.multi) { | ||
var fieldValue = _this.state.value; | ||
@@ -101,42 +101,30 @@ // Append the option if it was selected | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* The field loaded | ||
* @param field - The field information. | ||
* @param state - The current state. | ||
*/ | ||
_this.onFieldInit = function (field, state) { | ||
var choiceField = field; | ||
// Ensure this is a choice field | ||
if (field.FieldTypeKind != gd_sprest_1.SPTypes.FieldType.Choice && field.FieldTypeKind != gd_sprest_1.SPTypes.FieldType.MultiChoice) { | ||
// Log | ||
console.warn("[gd-sprest] The field '" + field.InternalName + "' is not a choice field."); | ||
return; | ||
} | ||
// Update the state | ||
state.fieldInfo.choices = choiceField.Choices; | ||
state.fieldInfo.multiChoice = choiceField.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.MultiChoice; | ||
state.options = _this.toOptions(); | ||
// See if the default value is provided | ||
if (_this.props.defaultValue) { | ||
_this.onFieldLoaded = function (info, state) { | ||
var fldInfo = info; | ||
// Set the choices | ||
state.options = _this.toOptions(fldInfo); | ||
// Set the default value | ||
state.value = _this.props.defaultValue; | ||
// See if this is a new form, and a default value exists | ||
if (_this.props.controlMode == gd_sprest_1.SPTypes.ControlMode.New && fldInfo.field.DefaultValue) { | ||
// Set the value | ||
state.value = _this.props.defaultValue; | ||
state.value = state.value || (fldInfo.multi ? { results: [fldInfo.field.DefaultValue] } : fldInfo.field.DefaultValue); | ||
} | ||
else if (_this.props.controlMode == gd_sprest_1.SPTypes.ControlMode.New && choiceField.DefaultValue) { | ||
// Set the value | ||
state.value = state.fieldInfo.multiChoice ? { results: [choiceField.DefaultValue] } : choiceField.DefaultValue; | ||
// See if no value exists for a multi choice field | ||
if (state.value == null && info.multi) { | ||
// Set a default value | ||
state.value = { results: [] }; | ||
} | ||
else { | ||
// Set the default value | ||
state.value = state.fieldInfo.multiChoice ? { results: [] } : null; | ||
} | ||
}; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to convert the field value to options | ||
*/ | ||
_this.toOptions = function () { | ||
_this.toOptions = function (fldInfo) { | ||
var options = []; | ||
// See if this is not a required multi-choice field | ||
if (!_this.state.fieldInfo.required && !_this.state.fieldInfo.multiChoice) { | ||
if (!fldInfo.required && !fldInfo.multi) { | ||
// Add a blank option | ||
@@ -149,4 +137,4 @@ options.push({ | ||
// Parse the choices | ||
for (var i = 0; i < _this.state.fieldInfo.choices.results.length; i++) { | ||
var choice = _this.state.fieldInfo.choices.results[i]; | ||
for (var i = 0; i < fldInfo.choices.length; i++) { | ||
var choice = fldInfo.choices[i]; | ||
// Add the option | ||
@@ -153,0 +141,0 @@ options.push({ |
@@ -16,10 +16,8 @@ import { IFieldDateTime, IFieldDateTimeProps, IFieldDateTimeState } from "../definitions"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param state - The current state. | ||
* Method to get the value | ||
*/ | ||
onFieldInit: (field: any, state: IFieldDateTimeState) => void; | ||
private getValue; | ||
/** | ||
@@ -36,9 +34,2 @@ * The date changed event | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to get the value | ||
*/ | ||
private getValue; | ||
/** | ||
* Method to render the time component | ||
@@ -45,0 +36,0 @@ * @param date - The date/time value |
@@ -50,3 +50,3 @@ "use strict"; | ||
props.isRequired = typeof (props.isRequired) === "boolean" ? props.isRequired : _this.state.fieldInfo.required; | ||
props.label = _this.state.label; | ||
props.label = _this.state.fieldInfo.title; | ||
props.onSelectDate = _this.state.fieldInfo.showTime ? _this.onDateChanged : _this.updateValue; | ||
@@ -62,12 +62,23 @@ props.placeholder = props.placeholder || "Date"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param state - The current state. | ||
* Method to get the value | ||
*/ | ||
_this.onFieldInit = function (field, state) { | ||
// Update the state | ||
state.fieldInfo.showTime = field.DisplayFormat == gd_sprest_1.SPTypes.DateFormat.DateTime; | ||
_this.getValue = function () { | ||
// Get the value | ||
var value = _this.getFieldValue(); | ||
if (value && typeof (value) === "string") { | ||
// See if the default value is set to today | ||
if (value == "[today]") { | ||
// Return the current date/time | ||
return new Date(Date.now()); | ||
} | ||
else { | ||
// Convert the value | ||
return new Date(value); | ||
} | ||
} | ||
// Return the value | ||
return value; | ||
}; | ||
@@ -104,25 +115,2 @@ /** | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to get the value | ||
*/ | ||
_this.getValue = function () { | ||
// Get the value | ||
var value = _this.getFieldValue(); | ||
if (value && typeof (value) === "string") { | ||
// See if the default value is set to today | ||
if (value == "[today]") { | ||
// Return the current date/time | ||
return new Date(Date.now()); | ||
} | ||
else { | ||
// Convert the value | ||
return new Date(value); | ||
} | ||
} | ||
// Return the value | ||
return value; | ||
}; | ||
/** | ||
* Method to render the time component | ||
@@ -129,0 +117,0 @@ * @param date - The date/time value |
@@ -13,3 +13,3 @@ import { IDropdownOption } from "office-ui-fabric-react"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -24,15 +24,7 @@ /** | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param field - The field information. | ||
* @param state - The current state. | ||
*/ | ||
onFieldInit: (field: any, state: IFieldLookupState) => void; | ||
onFieldLoaded: (info: any, state: IFieldLookupState) => void; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to load the lookup items | ||
* @param fieldInfo - The field information. | ||
*/ | ||
private loadLookupItems; | ||
/** | ||
* Method to convert the field value to options | ||
@@ -39,0 +31,0 @@ * @param items - The lookup items. |
@@ -55,13 +55,13 @@ "use strict"; | ||
props.disabled = _this.state.fieldInfo.readOnly || _this.props.controlMode == gd_sprest_1.SPTypes.ControlMode.Display; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.fieldInfo.errorMessage; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.errorMessage; | ||
props.errorMessage = _this.state.showErrorMessage ? (props.selectedKey ? "" : props.errorMessage) : ""; | ||
props.label = props.label ? props.label : _this.state.label; | ||
props.multiSelect = _this.state.fieldInfo.allowMultipleValues; | ||
props.label = props.label ? props.label : _this.state.fieldInfo.title; | ||
props.multiSelect = _this.state.fieldInfo.multi; | ||
props.onChanged = _this.onChanged; | ||
props.options = _this.state.options; | ||
props.required = props.required || _this.state.fieldInfo.required; | ||
// See if this is a multi-choice | ||
// See if we are allowing multiple values | ||
if (props.multiSelect) { | ||
// Set the selected keys | ||
props.defaultSelectedKeys = _this.state.value.results; | ||
props.defaultSelectedKeys = _this.state.value ? _this.state.value.results : null; | ||
} | ||
@@ -76,3 +76,3 @@ else { | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -86,3 +86,3 @@ /** | ||
// See if this is a multi-choice field | ||
if (_this.state.fieldInfo.allowMultipleValues) { | ||
if (_this.state.fieldInfo.multi) { | ||
var fieldValue = _this.state.value; | ||
@@ -113,20 +113,11 @@ // Append the option if it was selected | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param field - The field information. | ||
* @param state - The current state. | ||
*/ | ||
_this.onFieldInit = function (field, state) { | ||
var lookupField = field; | ||
// Ensure this is a lookup field | ||
if (lookupField.FieldTypeKind != gd_sprest_1.SPTypes.FieldType.Lookup) { | ||
// Log | ||
console.warn("[gd-sprest] The field '" + field.InternalName + "' is not a lookup field."); | ||
return; | ||
} | ||
// Update the field information | ||
state.fieldInfo.allowMultipleValues = lookupField.AllowMultipleValues; | ||
state.fieldInfo.lookupFieldName = lookupField.LookupField; | ||
state.fieldInfo.lookupListName = lookupField.LookupList; | ||
state.fieldInfo.lookupWebId = lookupField.LookupWebId; | ||
_this.onFieldLoaded = function (info, state) { | ||
var fldInfo = info; | ||
// Set the value | ||
state.value = _this.props.defaultValue || fldInfo.defaultValue; | ||
// See if this is an associated lookup field | ||
if (lookupField.ReadOnlyField) { | ||
if (fldInfo.readOnly) { | ||
// Set the options | ||
@@ -137,25 +128,6 @@ state.options = []; | ||
// Load the lookup data | ||
_this.loadLookupItems(state.fieldInfo).then(function (fieldInfo) { | ||
var value = null; | ||
// See if this is a multi-lookup field and a value exists | ||
if (fieldInfo.allowMultipleValues) { | ||
var results = []; | ||
// Parse the values | ||
var values = _this.props.defaultValue ? _this.props.defaultValue.results : []; | ||
for (var i = 0; i < values.length; i++) { | ||
// Add the item id | ||
results.push(values[i].ID || values[i]); | ||
} | ||
// Set the default value | ||
value = { results: results }; | ||
} | ||
else { | ||
// Set the default value | ||
value = _this.props.defaultValue ? _this.props.defaultValue.ID || _this.props.defaultValue : null; | ||
} | ||
gd_sprest_1.Helper.ListFormField.loadLookupData(fldInfo).then(function (items) { | ||
// Update the state | ||
_this.setState({ | ||
fieldInfo: fieldInfo, | ||
options: _this.toOptions(fieldInfo.items, fieldInfo.lookupFieldName), | ||
value: value | ||
options: _this.toOptions(items, fldInfo.lookupField) | ||
}); | ||
@@ -166,34 +138,2 @@ }); | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to load the lookup items | ||
* @param fieldInfo - The field information. | ||
*/ | ||
_this.loadLookupItems = function (fieldInfo) { | ||
// Return a promise | ||
return new Promise(function (resolve, reject) { | ||
// Get the current site collection | ||
(new gd_sprest_1.Site()) | ||
.openWebById(fieldInfo.lookupWebId) | ||
.execute(function (web) { | ||
// Get the list | ||
web.Lists() | ||
.getById(fieldInfo.lookupListName) | ||
.Items() | ||
.query({ | ||
GetAllItems: true, | ||
Select: ["ID", fieldInfo.lookupFieldName], | ||
Top: _this.props.queryTop > 0 && _this.props.queryTop <= 5000 ? _this.props.queryTop : 500 | ||
}) | ||
.execute(function (items) { | ||
// Update the field information | ||
fieldInfo.items = items.results || []; | ||
// Resolve the promise | ||
resolve(fieldInfo); | ||
}); | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Method to convert the field value to options | ||
@@ -207,3 +147,3 @@ * @param items - The lookup items. | ||
// See if this is not a required multi-lookup field | ||
if (!_this.state.fieldInfo.required && !_this.state.fieldInfo.allowMultipleValues) { | ||
if (!_this.state.fieldInfo.required && !_this.state.fieldInfo.multi) { | ||
// Add a blank option | ||
@@ -210,0 +150,0 @@ options.push({ |
@@ -13,3 +13,3 @@ import { IDropdownOption } from "office-ui-fabric-react"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -23,21 +23,8 @@ /** | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* The field loaded event | ||
* @param info - The field information. | ||
* @param state - The current state. | ||
*/ | ||
onFieldInit: (field: any, state: IFieldManagedMetadataState) => void; | ||
onFieldLoaded: (info: any, state: IFieldManagedMetadataState) => void; | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to load the value field | ||
* @param fieldInfo - The field information. | ||
*/ | ||
private loadValueField; | ||
/** | ||
* Method to load the terms | ||
* @param fieldInfo - The field information. | ||
*/ | ||
private loadTerms; | ||
/** | ||
* Method to convert the field value to options | ||
@@ -44,0 +31,0 @@ * @param terms - The managed metadata terms. |
@@ -49,10 +49,10 @@ "use strict"; | ||
props.disabled = _this.state.fieldInfo.readOnly || _this.props.controlMode == gd_sprest_1.SPTypes.ControlMode.Display; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.fieldInfo.errorMessage; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.errorMessage; | ||
props.errorMessage = _this.state.showErrorMessage ? (props.selectedKey ? "" : props.errorMessage) : ""; | ||
props.label = props.label ? props.label : _this.state.label; | ||
props.multiSelect = _this.state.fieldInfo.allowMultipleValues; | ||
props.multiSelect = _this.state.fieldInfo.multi; | ||
props.label = props.label ? props.label : _this.state.fieldInfo.title; | ||
props.onChanged = _this.onChanged; | ||
props.options = _this.state.options; | ||
props.required = props.required || _this.state.fieldInfo.required; | ||
// See if this is a multi-choice | ||
// See if we are allowing multiple values | ||
if (props.multiSelect) { | ||
@@ -76,3 +76,3 @@ var keys = []; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -86,3 +86,3 @@ /** | ||
// See if this is a multi-choice field | ||
if (_this.state.fieldInfo.allowMultipleValues) { | ||
if (_this.state.fieldInfo.multi) { | ||
var fieldValue = _this.state.value; | ||
@@ -121,25 +121,15 @@ // Append the option if it was selected | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* The field loaded event | ||
* @param info - The field information. | ||
* @param state - The current state. | ||
*/ | ||
_this.onFieldInit = function (field, state) { | ||
var mmsField = field; | ||
// Ensure this is a lookup field | ||
if (mmsField.TypeAsString != state.fieldInfo.typeAsString) { | ||
// Log | ||
console.warn("[gd-sprest] The field '" + field.InternalName + "' is not a lookup field."); | ||
return; | ||
} | ||
// Update the field information | ||
state.fieldInfo.allowMultipleValues = mmsField.AllowMultipleValues; | ||
state.fieldInfo.termSetId = mmsField.TermSetId; | ||
state.fieldInfo.termStoreId = mmsField.SspId; | ||
// Load the hidden field | ||
_this.loadValueField(state.fieldInfo).then(function (fieldInfo) { | ||
// Load the value field | ||
_this.loadTerms(state.fieldInfo).then(function (fieldInfo) { | ||
_this.onFieldLoaded = function (info, state) { | ||
var fldInfo = info; | ||
// Load the value field | ||
gd_sprest_1.Helper.ListFormField.loadMMSValueField(fldInfo).then(function (valueField) { | ||
// Load the terms | ||
gd_sprest_1.Helper.ListFormField.loadMMSData(fldInfo).then(function (terms) { | ||
var value = null; | ||
// See if this is a multi-lookup field and a value exists | ||
if (fieldInfo.allowMultipleValues) { | ||
if (fldInfo.multi) { | ||
var results = []; | ||
@@ -164,3 +154,3 @@ // Parse the values | ||
// Set the default value | ||
value = _this.props.defaultValue ? _this.props.defaultValue : null; | ||
value = fldInfo.defaultValue ? fldInfo.defaultValue : null; | ||
} | ||
@@ -171,5 +161,5 @@ // Add the metadata | ||
_this.setState({ | ||
fieldInfo: fieldInfo, | ||
options: _this.toOptions(fieldInfo.terms), | ||
value: value | ||
options: _this.toOptions(terms), | ||
value: value, | ||
valueField: valueField | ||
}); | ||
@@ -180,99 +170,2 @@ }); | ||
/** | ||
* Methods | ||
*/ | ||
/** | ||
* Method to load the value field | ||
* @param fieldInfo - The field information. | ||
*/ | ||
_this.loadValueField = function (fieldInfo) { | ||
// Return a promise | ||
return new Promise(function (resolve, reject) { | ||
// See if we are allowing multiple values | ||
if (fieldInfo.allowMultipleValues) { | ||
// Get the web | ||
(new gd_sprest_1.Web(fieldInfo.webUrl)) | ||
.Lists(fieldInfo.listName) | ||
.Fields() | ||
.getByInternalNameOrTitle(fieldInfo.name + "_0") | ||
.execute(function (field) { | ||
// See if the field exists | ||
if (field.existsFl) { | ||
// Set the value field | ||
fieldInfo.valueField = field.InternalName; | ||
// Resolve the promise | ||
resolve(fieldInfo); | ||
} | ||
else { | ||
// Log | ||
console.log("[gd-sprest] Unable to find the hidden value field for '" + fieldInfo.name + "'."); | ||
} | ||
}); | ||
} | ||
else { | ||
// Resolve the promise | ||
resolve(fieldInfo); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Method to load the terms | ||
* @param fieldInfo - The field information. | ||
*/ | ||
_this.loadTerms = function (fieldInfo) { | ||
// Return a promise | ||
return new Promise(function (resolve, reject) { | ||
// Ensure the utility class is loaded | ||
SP.SOD.executeFunc("sp.js", "SP.Utilities.Utility", function () { | ||
// Ensure the taxonomy script is loaded | ||
SP.SOD.registerSod("sp.taxonomy.js", SP.Utilities.Utility.getLayoutsPageUrl("sp.taxonomy.js")); | ||
SP.SOD.executeFunc("sp.taxonomy.js", "SP.Taxonomy.TaxonomySession", function () { | ||
// Load the terms | ||
var context = SP.ClientContext.get_current(); | ||
var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context); | ||
var termStore = session.get_termStores().getById(fieldInfo.termStoreId); | ||
var termSet = termStore.getTermSet(fieldInfo.termSetId); | ||
var terms = termSet.getAllTerms(); | ||
context.load(terms); | ||
// Execute the request | ||
context.executeQueryAsync( | ||
// Success | ||
function () { | ||
// Clear the terms | ||
fieldInfo.terms = []; | ||
// Parse the terms | ||
var enumerator = terms.getEnumerator(); | ||
while (enumerator.moveNext()) { | ||
var term = enumerator.get_current(); | ||
// Add the term information | ||
fieldInfo.terms.push({ | ||
id: term.get_id().toString(), | ||
name: term.get_name(), | ||
path: term.get_pathOfTerm().replace(/;/g, "/") | ||
}); | ||
} | ||
// Sort the terms | ||
fieldInfo.terms.sort(function (a, b) { | ||
if (a.path < b.path) { | ||
return -1; | ||
} | ||
if (a.path > b.path) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
// Resolve the request | ||
resolve(fieldInfo); | ||
}, | ||
// Error | ||
function () { | ||
// Log | ||
console.log("[gd-sprest] Error getting the term set terms."); | ||
// Resolve the request | ||
resolve(fieldInfo); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Method to convert the field value to options | ||
@@ -285,3 +178,3 @@ * @param terms - The managed metadata terms. | ||
// See if this is not a required multi-lookup field | ||
if (!_this.state.fieldInfo.required && !_this.state.fieldInfo.allowMultipleValues) { | ||
if (!_this.state.fieldInfo.required && !_this.state.fieldInfo.multi) { | ||
// Add a blank option | ||
@@ -288,0 +181,0 @@ options.push({ |
@@ -23,8 +23,2 @@ import { IFieldNumberProps, IFieldNumberState } from "../definitions"; | ||
onChange: (value: number) => void; | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param state - The current state. | ||
*/ | ||
onFieldInit: (field: any, state: IFieldNumberState) => void; | ||
} |
@@ -45,4 +45,4 @@ "use strict"; | ||
props.disabled = _this.state.fieldInfo.readOnly || _this.props.controlMode == gd_sprest_1.SPTypes.ControlMode.Display; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.fieldInfo.errorMessage; | ||
props.label = props.label ? props.label : _this.state.label; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.errorMessage; | ||
props.label = props.label ? props.label : _this.state.fieldInfo.title; | ||
props.onChanged = _this.updateValue; | ||
@@ -96,28 +96,2 @@ props.required = typeof (props.required) === "boolean" ? props.required : _this.state.fieldInfo.required; | ||
}; | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param state - The current state. | ||
*/ | ||
_this.onFieldInit = function (field, state) { | ||
var numberField = field; | ||
// Ensure this is a number field | ||
if (numberField.FieldTypeKind != gd_sprest_1.SPTypes.FieldType.Number) { | ||
// Log | ||
console.warn("[gd-sprest] The field '" + field.InternalName + "' is not a number field."); | ||
return; | ||
} | ||
// Update the field information | ||
state.fieldInfo.maxValue = numberField.MaximumValue; | ||
state.fieldInfo.minValue = numberField.MinimumValue; | ||
// See if the show as percentage property exists | ||
if (numberField.ShowAsPercentage != undefined) { | ||
// Update the property | ||
state.fieldInfo.showAsPercentage = numberField.ShowAsPercentage; | ||
} | ||
else { | ||
// Check the schema xml | ||
state.fieldInfo.showAsPercentage = numberField.SchemaXml.indexOf('Percentage="TRUE"') > 0; | ||
} | ||
}; | ||
return _this; | ||
@@ -124,0 +98,0 @@ } |
@@ -12,11 +12,5 @@ import { IFieldTextProps, IFieldTextState } from "../definitions"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param state - The current state. | ||
*/ | ||
onFieldInit: (field: any, state: IFieldTextState) => void; | ||
/** | ||
* The on change event | ||
@@ -23,0 +17,0 @@ * @param value - The field value. |
@@ -43,4 +43,4 @@ "use strict"; | ||
props.className = (_this.props.className || ""); | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.fieldInfo.errorMessage; | ||
props.label = props.label || _this.state.label; | ||
props.errorMessage = props.errorMessage ? props.errorMessage : _this.state.errorMessage; | ||
props.label = props.label || _this.state.fieldInfo.title; | ||
props.multiline = typeof (props.label) === "boolean" ? props.label : _this.state.fieldInfo.multiline; | ||
@@ -55,3 +55,3 @@ props.onChanged = _this.onChange; | ||
// Get the html | ||
var __html = _this.props.defaultValue || ""; | ||
var __html = props.value; | ||
__html = _this.state.fieldInfo.richText ? __html : __html.replace(/\r?\n/g, "<br/>"); | ||
@@ -67,22 +67,5 @@ // Render the value | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* @param state - The current state. | ||
*/ | ||
_this.onFieldInit = function (field, state) { | ||
// Ensure this is a lookup field | ||
if (field.FieldTypeKind != gd_sprest_1.SPTypes.FieldType.Note && field.FieldTypeKind != gd_sprest_1.SPTypes.FieldType.Text) { | ||
// Log | ||
console.warn("[gd-sprest] The field '" + field.InternalName + "' is not a text field."); | ||
return; | ||
} | ||
// Update the state | ||
state.fieldInfo.multiline = field.FieldTypeKind == gd_sprest_1.SPTypes.FieldType.Note; | ||
state.fieldInfo.richText = field.RichText; | ||
state.fieldInfo.rows = field.NumberOfLines; | ||
}; | ||
/** | ||
* The on change event | ||
@@ -89,0 +72,0 @@ * @param value - The field value. |
@@ -12,3 +12,3 @@ import { IFieldUrlProps, IFieldUrlState } from "../definitions"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -15,0 +15,0 @@ /** |
@@ -47,3 +47,3 @@ "use strict"; | ||
urlProps.placeholder = urlProps.placeholder ? urlProps.placeholder : "Url"; | ||
urlProps.label = urlProps.label || _this.state.label; | ||
urlProps.label = urlProps.label || _this.state.fieldInfo.title; | ||
urlProps.onChanged = _this.onUrlChanged; | ||
@@ -55,3 +55,3 @@ urlProps.required = typeof (urlProps.required) === "boolean" ? urlProps.required : _this.state.fieldInfo.required; | ||
descProps.disabled = _this.props.controlMode == gd_sprest_1.SPTypes.ControlMode.Display; | ||
descProps.errorMessage = descProps.errorMessage ? descProps.errorMessage : _this.state.fieldInfo.errorMessage; | ||
descProps.errorMessage = descProps.errorMessage ? descProps.errorMessage : _this.state.errorMessage; | ||
descProps.errorMessage = _this.state.showErrorMessage ? (urlProps.defaultValue ? "" : descProps.errorMessage) : ""; | ||
@@ -71,3 +71,3 @@ descProps.onChanged = _this.onDescChanged; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -74,0 +74,0 @@ /** |
@@ -12,3 +12,3 @@ import { IFieldUserProps, IFieldUserState } from "../definitions"; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -21,7 +21,7 @@ /** | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* The field loaded event | ||
* @param info - The field information. | ||
* @param state - The current state. | ||
*/ | ||
onFieldInit: (field: any, state: IFieldUserState) => void; | ||
onFieldLoaded: (info: any, state: IFieldUserState) => void; | ||
} |
@@ -50,7 +50,7 @@ "use strict"; | ||
return (React.createElement("div", { className: (_this.props.className || "") }, | ||
React.createElement(office_ui_fabric_react_1.Label, __assign({}, lblProps), lblProps.defaultValue || _this.state.label), | ||
React.createElement(__1.SPPeoplePicker, { allowGroups: _this.state.fieldInfo.allowGroups, allowMultiple: _this.state.fieldInfo.allowMultiple, fieldValue: _this.props.defaultValue ? _this.props.defaultValue.results || [_this.props.defaultValue] : null, props: props }))); | ||
React.createElement(office_ui_fabric_react_1.Label, __assign({}, lblProps), lblProps.defaultValue || _this.state.fieldInfo.title), | ||
React.createElement(__1.SPPeoplePicker, { allowGroups: _this.state.fieldInfo.allowGroups, allowMultiple: _this.state.fieldInfo.multi, fieldValue: _this.state.value ? _this.state.value.results || [_this.state.value] : null, props: props }))); | ||
}; | ||
/** | ||
* Events | ||
* Methods | ||
*/ | ||
@@ -63,25 +63,18 @@ /** | ||
// Update the field value | ||
_this.updateValue(__1.SPPeoplePicker.convertToFieldValue(personas, _this.state.fieldInfo.allowMultiple)); | ||
_this.updateValue(__1.SPPeoplePicker.convertToFieldValue(personas, _this.state.fieldInfo.multi)); | ||
}; | ||
/** | ||
* The field initialized event | ||
* @param field - The field. | ||
* The field loaded event | ||
* @param info - The field information. | ||
* @param state - The current state. | ||
*/ | ||
_this.onFieldInit = function (field, state) { | ||
var userField = field; | ||
// Ensure this is a lookup field | ||
if (userField.FieldTypeKind != gd_sprest_1.SPTypes.FieldType.User) { | ||
// Log | ||
console.warn("[gd-sprest] The field '" + userField.InternalName + "' is not a user field."); | ||
return; | ||
} | ||
// Update the state | ||
state.fieldInfo.allowMultiple = userField.AllowMultipleValues; | ||
state.fieldInfo.allowGroups = userField.SelectionMode == gd_sprest_1.SPTypes.FieldUserSelectionType.PeopleAndGroups; | ||
_this.onFieldLoaded = function (info, state) { | ||
var fldInfo = info; | ||
// Default the value | ||
state.value = _this.props.defaultValue || fldInfo.defaultValue; | ||
// See if this is a multi-lookup field | ||
if (state.fieldInfo.allowMultiple) { | ||
if (fldInfo.multi) { | ||
var results = []; | ||
// Parse the users | ||
var users = (_this.props.defaultValue ? _this.props.defaultValue.results : _this.props.defaultValue) || []; | ||
var users = (state.value ? state.value.results : state.value) || []; | ||
for (var i = 0; i < users.length; i++) { | ||
@@ -96,3 +89,3 @@ // Add the item id | ||
// Set the value | ||
state.value = _this.props.defaultValue ? _this.props.defaultValue.ID || _this.props.defaultValue : null; | ||
state.value = state.value || state.value.ID; | ||
} | ||
@@ -99,0 +92,0 @@ }; |
{ | ||
"name": "gd-sprest-react", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"description": "SharePoint react components.", | ||
@@ -41,3 +41,3 @@ "main": "build/index.js", | ||
"css-loader": "^0.28.8", | ||
"gd-sprest": "^2.9.6", | ||
"gd-sprest": "^2.9.8", | ||
"node-sass": "^4.7.2", | ||
@@ -44,0 +44,0 @@ "office-ui-fabric-react": "^5.39.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
355825
6111