Google App maker user picker validation

848 Views Asked by At

In App maker user picker widget is populating the users added in the organization. But it is not throwing any error when a valid value is not entered in the field. It just saves as an empty field. How to use the Validation display and Validation error message when an error encountered. I want display different error message when a particular error occurs.

1

There are 1 best solutions below

4
On BEST ANSWER

First of all, you can enforce it on Model level by making the field required. Secondary, you can add your custom validation logic on UI:

// UserPicker onValidate event
if (widget.value === null || widget.value === '') {
  return 'validation error message goes here';
}

Be sure, that your form's submit button is bound to @widget.parent.parent.valid (it is default App Maker binding for forms) or forces validation on click:

// submit button onClick event for AM auto-generated form
if (widget.parent.parent.validate()) {
  widget.datasource.createItem();
}

This will trigger onValidate event for the UserPicker widget.