Skip to content

Commit

Permalink
Merge pull request #2784 from bcameron1231/fix-2783
Browse files Browse the repository at this point in the history
Bug Fix for 2783
  • Loading branch information
juliemturner authored Sep 23, 2023
2 parents a543bf8 + 00307c2 commit e29b6a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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

0 comments on commit e29b6a9

Please sign in to comment.