- You want to create the text item to the active Google Form.
- You want to give the validation rule to the text item.
- You want to use the values from Google Spreadsheet as the validation rule.
- You want to make users input the values which are the same with the values retrieved from Google Spreadsheet.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Modification points:
- In this case, it is required to create the value of the validation. Then, the created validation rule is put to the text time and add it to the Google Form.
Modified script:
When your script is modified, it becomes as follows.
var idVal = Formapp.createTextValidation();
.setHelpText("Inserisci un codice identificativo valido.");
.???
var pattern = "^" + idValues.map(function([e]) {return e}).filter(String).join("|") + "$";
var idVal = FormApp.createTextValidation().requireTextMatchesPattern(pattern).build();
form.addTextItem()
.setHelpText("Inserisci un codice identificativo valido.")
.setValidation(idVal)
.setTitle("title");
Note:
- In this modified script, it supposes that the values of
idValues
have the values you expect.
In this case, when the inputted values are the same with the list of values retrieved from the Spreadsheet, the values can be inputted. If you want to use contains
, please modify pattern
and idVal
in above script as follows.
var pattern = idValues.map(function([e]) {return e}).filter(String).join("|");
var idVal = FormApp.createTextValidation().requireTextContainsPattern(pattern).build();
References:
Added:
For example, when you want to add the varidation to the existing items, how about the following script? In this case, please replace above script as follows.
From:
form.addTextItem()
.setHelpText("Inserisci un codice identificativo valido.")
.setValidation(idVal)
.setTitle("title");
To:
form.getItemById(itemId).asTextItem()
.setHelpText("Inserisci un codice identificativo valido.")
.setValidation(idVal)
.setTitle("title");
or
form.getItems()[0].asTextItem()
.setHelpText("Inserisci un codice identificativo valido.")
.setValidation(idVal)
.setTitle("title");
compare them with the user text entry in the validation
? – Tanaike