alep
alep

Reputation: 135

How to do binding for drop down and checkbox in App Maker?

From the screenshot of my form:

enter image description here

  1. How to do the binding to Contract Type from dropdown list option or if user key in input in the label next to it if the option is not listed in the drop-down?
  2. How to do binding for the checkbox option?

Upvotes: 0

Views: 650

Answers (1)

Pavel Shkleinik
Pavel Shkleinik

Reputation: 6347

For Dropdown-Input combo I would go with two model fields: ContractType and CustomContractType. For the ContractType I would specify possibleValues (Type One, Type Two, Type Three, ..., Other) in advanced field settings and bind them to Dropdown's options:

@models.ModelName.fields.ContractType.possibleValues

and bind value to ContractType field:

@datasource.item.ContractType

Then I would bind visible or enabled Input's property to

@datasource.item.ContractType === 'Other'

and bind value to CustomContractType field:

@datasource.item.CustomContractType

and enforce this logic in onBeforeCreate and onBeforeSave model events:

if (record.ContractType !== 'Other' && record.CustomContractType !== null) {
  record.CustomContractType = null; // or throw exception...
}

if (record.ContractType === 'Other' && record.CustomContractType === null) {
  throw new Error('CustomContractType is required');
}

Renewal notice(notices?)

In case you need to select only one renewal notice, I would recommend to use Radio Group widget. Otherwise you can keep using multiple checkboxes and introduce multiple model fields for each checkbox OR use Multiselect select widget and try to mate it with string model's field in combination with split binding transformer (you can find sample in Document Approval template, Admin/Settings page).

Upvotes: 1

Related Questions