michoel
11/26/2020, 12:51 AMconst field = form.addField({
id: "custpage_my_field",
label: "Field Label",
type: ui.FieldType.TEXT,
});
field.isMandatory = true;
field.defaultValue = "Hello";
field.helpText = "Help Text Here";
field.updateDisplayType({ displayType: ui.FieldDisplayType.INLINE });
I've written a simple wrapper around addField that accepts a single parameter for everything (code in thread)
addField(form, {
id: "custpage_my_field",
label: "Field Label",
type: ui.FieldType.TEXT,
isMandatory: true,
defaultValue: "Hello",
helpText: "Help Text Here",
displayType: ui.FieldDisplayType.INLINE,
});
Would love to hear if anyone else has this same gripe and if you think this is approach lends to cleaner/clearer code or you would find it more confusing?michoel
11/26/2020, 12:52 AMfunction addField(formOrSublist, options) {
const validFieldOptions = ["id", "label", "type", "source", "container"];
const validFieldProperties = [
"isMandatory",
"helpText",
"defaultValue",
"linkText",
"maxLength",
"richTextHeight",
"richTextHeight",
"padding",
];
const validUpdateMethods = ["breakType", "displaySize", "displayType", "layoutType"];
const fieldOptions = pick(options, validFieldOptions);
const fieldProperties = pick(options, validFieldProperties);
const updateMethods = pick(options, validUpdateMethods);
const field = formOrSublist.addField(fieldOptions);
for (const [key, value] of Object.entries(fieldProperties)) {
field[key] = value;
}
for (const [key, value] of Object.entries(updateMethods)) {
const updateMethodName = `update${key.charAt(0).toUpperCase()}${key.slice(1)}`;
const options = typeof value === "object" ? value : { [key]: value };
field[updateMethodName](options);
}
if (options.hasOwnProperty("selectOptions")) {
options.selectOptions.forEach((selectOption) => field.addSelectOption(selectOption));
}
return field;
}
battk
11/26/2020, 12:54 AMmichoel
11/26/2020, 12:56 AMbattk
11/26/2020, 12:57 AMbattk
11/26/2020, 1:04 AMmichoel
11/26/2020, 1:06 AMbattk
11/26/2020, 1:08 AMmichoel
11/26/2020, 1:08 AMbattk
11/26/2020, 1:08 AMmichoel
11/26/2020, 1:09 AM{
label: "Amount Remaining Operator",
id: "custpage_amount_remaining_op_filter",
type: ui.FieldType.SELECT,
container: "custpage_search_filters",
selectOptions: [
{ value: "lessThan", text: "< (Less Than)", isSelected: true },
{ value: "equalTo", text: "= (Equal To)" },
{ value: "greaterThan", text: "> (Greater Than)" },
],
helpText:
"If you are filtering by Amount Remaining, select if the filter should look for values less than, more than or equal to the amount entered in that field",
}
michoel
11/26/2020, 1:09 AMisSelected
for select options instead of defaultValue
battk
11/26/2020, 1:12 AMbattk
11/26/2020, 1:13 AMvar restrictToScriptIdField = serverWidgetUtil.addField(
restrictToScriptIdsSublist,
_.assign(
{
type: serverWidget.FieldType.SELECT,
source: "-417", // TODO find a better id for Script
isMandatory: true,
},
fields.restrictToScriptId
)
);
battk
11/26/2020, 1:14 AM{
id: "custpage_restrict_to_script_ids",
label: "Restrict to Script Ids",
helpText: "Select the scripts that are allowed to use the GUID.",
}
michoel
11/26/2020, 1:16 AMjen
11/27/2020, 10:03 PMstalbert
11/30/2020, 2:31 PMstalbert
11/30/2020, 2:32 PMSandii
11/30/2020, 3:19 PMstalbert
11/30/2020, 3:27 PM