Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix for 2783 #2784

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/sp/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,31 @@ const r = await field.field.select("Id")();
console.log(r.Id);
```

### Add an Image Field

Use the addImageField method to create a new image field.

```TypeScript
import { spfi } from "@pnp/sp";
import { IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/fields";

const sp = spfi(...);

// create a new image field called 'My Field' in web.
const field: IFieldAddResult = await sp.web.fields.addImageField("My Field");
// create a new image field called 'My Field' in the list 'My List'.
const field2: IFieldAddResult = await sp.web.lists.getByTitle("My List").fields.addImageField("My Field");

// we can use this 'field' variable to run more queries on the field:
const r = await field.field.select("Id")();

// log the field Id to console
console.log(r.Id);
```

### Add a Multi-line Text Field

Use the addMultilineText method to create a new multi-line text field.
Expand Down
2 changes: 1 addition & 1 deletion packages/sp/fields/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ const FieldTypeClassMapping = {
[FieldTypes.DateTime]:"SP.FieldDateTime",
[FieldTypes.GridChoice]:"SP.FieldRatingScale",
[FieldTypes.Guid]: "SP.FieldGuid",
[FieldTypes.Image]:"FieldMultiLineText",
[FieldTypes.Image]:"SP.FieldMultiLineText",
[FieldTypes.Integer]:"SP.FieldNumber",
[FieldTypes.Location]:"SP.FieldLocation",
[FieldTypes.Lookup]:"SP.FieldLookup",
Expand Down
5 changes: 5 additions & 0 deletions test/sp/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe("Fields", function () {
const field = await this.pnp.sp.web.fields.addText(testFieldNameRand, { Group: testFieldGroup });
return expect(field.data.Title).to.be.equal(testFieldNameRand);
});
it("addImageField", async function () {
const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`;
const field = await this.pnp.sp.web.fields.addImageField(testFieldNameRand, { Group: testFieldGroup});
return expect(field.data.Title).to.be.equal(testFieldNameRand);
});
it("addNumber", async function () {
const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`;
const field = await this.pnp.sp.web.fields.addNumber(testFieldNameRand, { Group: testFieldGroup });
Expand Down
Loading