Skip to content

Commit

Permalink
🤖 Merge PR #61785 [google-apps-script] Added missing .build() defin…
Browse files Browse the repository at this point in the history
…itions to the validation builders by @TimCreasman

* Added missing `.build()` definitions to the validation builders.

* Added tests for the FormApp validation builders.

Co-authored-by: Tim Creasman <tcreasman@pattern.health>
  • Loading branch information
TimCreasman and Tim Creasman committed Aug 18, 2022
1 parent 6a0b6fb commit 9205f79
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion types/google-apps-script/google-apps-script.forms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ declare namespace GoogleAppsScript {
*/
interface CheckboxGridValidationBuilder {
requireLimitOneResponsePerColumn(): CheckboxGridValidationBuilder;
build(): CheckboxGridValidation;
}
/**
* A question item that allows the respondent to select one or more checkboxes, as well as an
Expand Down Expand Up @@ -173,6 +174,7 @@ declare namespace GoogleAppsScript {
requireSelectAtLeast(number: Integer): CheckboxValidationBuilder;
requireSelectAtMost(number: Integer): CheckboxValidationBuilder;
requireSelectExactly(number: Integer): CheckboxValidationBuilder;
build(): CheckboxValidation;
}
/**
* A single choice associated with a type of Item that supports choices, like CheckboxItem, ListItem, or MultipleChoiceItem.
Expand Down Expand Up @@ -534,6 +536,7 @@ declare namespace GoogleAppsScript {
*/
interface GridValidationBuilder {
requireLimitOneResponsePerColumn(): GridValidationBuilder;
build(): GridValidation;
}
/**
* A layout item that displays an image. Items can be accessed or created from a Form.
Expand Down Expand Up @@ -837,7 +840,8 @@ declare namespace GoogleAppsScript {
* var paragraphTextItem = form.addParagraphTextItem().setTitle('Describe yourself:');
* var paragraphtextValidation = FormApp.createParagraphTextValidation()
* .setHelpText(“Answer must be more than 100 characters.”)
* .requireTextLengthGreatherThan(100);
* .requireTextLengthLessThanOrEqualTo(100)
* .build();
* paragraphTextItem.setValidation(paragraphtextValidation);
*/
interface ParagraphTextValidationBuilder {
Expand All @@ -847,6 +851,7 @@ declare namespace GoogleAppsScript {
requireTextLengthGreaterThanOrEqualTo(number: Integer): ParagraphTextValidationBuilder;
requireTextLengthLessThanOrEqualTo(number: Integer): ParagraphTextValidationBuilder;
requireTextMatchesPattern(pattern: string): ParagraphTextValidationBuilder;
build(): ParagraphTextValidation;
}
/**
* The bean implementation of a Feedback, which contains properties common to all feedback, such as
Expand Down Expand Up @@ -1012,6 +1017,7 @@ declare namespace GoogleAppsScript {
requireTextLengthLessThanOrEqualTo(number: Integer): TextValidationBuilder;
requireTextMatchesPattern(pattern: string): TextValidationBuilder;
requireWholeNumber(): TextValidationBuilder;
build(): TextValidation;
}
/**
* A question item that allows the respondent to indicate a time of day. Items can be accessed or
Expand Down
27 changes: 27 additions & 0 deletions types/google-apps-script/test/google-apps-script-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,30 @@ const onItemSelected = () => {
};

SlidesApp.getActivePresentation().getSlides()[0].setSkipped(true);

// Examples for form app validation builders:

// Example of building a text validation
const formAppTextValidation = FormApp.createTextValidation()
.requireNumberBetween(1, 100)
.build();

// Example of building a grid validation
const formAppGridValidation = FormApp.createGridValidation()
.requireLimitOneResponsePerColumn()
.build();

// Example of building a grid validation
const formAppCheckboxGridValidation = FormApp.createCheckboxGridValidation()
.requireLimitOneResponsePerColumn()
.build();

// Example of building a checkbox validation
const formAppCheckboxValidation = FormApp.createCheckboxValidation()
.requireSelectAtLeast(1)
.build();

// Example of building a paragraph text validation
const formAppParagraphTextValidation = FormApp.createParagraphTextValidation()
.requireTextDoesNotContainPattern('string')
.build();

0 comments on commit 9205f79

Please sign in to comment.