Make a field writable only if a certain value is set in another field
Imagine a scenario where you want to get the user’s favourite fruit:
The problem here is that our select list options probably don’t contain the names of all fruits, and there will always be a difficult person who wants something not on the list. What we’ll do is have an optionOther, which if selected, will make a free text field appear.
Or more realistically, this field could be the names of your Customers, and you might want to allow people to add additional ones.
We’ll create a text field calledFavourite Fruit (Other), which only becomes visible if theOtherselect list option is chosen. The, code to apply to theFavourite Fruitfield, is:
The behaviour is attached to the field to which we want to list for changes, in this caseFavourite Fruit, and not theFavourite Fruit (Other)field.
This example makes use ofgetFieldChanged(), which always returns the field ID of the field the behaviour fires for.
We can do a little bit more here for bonus points… we would like to create anOptionwith theothervalue, then update the issue to have this new option, and remove the value from theotherfield. To do this we use a listener on theIssue Updatedevent with the following code: