Default value of an attribute depending of another one in the same edit screen

Hi, Cuba Platform’s community

I’m novice in Cuba Platform development and I’m trying to assign the default value of an attribute depending on the value of another on entered previously in the same edit screen.

I have the attribute ‘Provider’ and the attribute ‘Commission’s Percentage’. After entering the value of the provider, the program has to obtain the commision’s percentage associated to this provider and offer this value as a default value for the ‘Commision’s Percentage’ attribute in the same editor screen.

But I don’t know where and how to implement this business logic, because I haven’t found and event or method which is executed after entering the value of an attribute in an edit screen to calculate the default value of another attribute.

I would be very grateful if someone could help me.

Hello, Xavier,
you have to inject the source field component to a screen controller and override controller’s init method. Call sourceField.addValueChangeListener and perform what you need in the closure. To modify attributes values just get entity which is being edited with getItem() and use its setters to do the job. I think all this is pretty well documented so you should be able to find more info how to do it exactly in docs.


Thanks, Ilia, for your support. I’ll try it.