Use of _target in live view in "handle_event"

Hi All.

I have a standard live view form with two fields whose values are dependent upon each other, meaning a change in one field updates the other. I therefore need to determine which of the fields the user has actually entered data in. Is there any problem in using the “_target” value passed to handle_event?

I ask because generally any value that starts with an underscore usually means it is an implementation detail and shouldn’t be relied on as it could change in the future.

[For info I can’t use get_change on the changeset as the user may have entered values in both fields so I need to know which field actually triggered the handle_event].

cheers

Dave

1 Like

Hi Dave,

The _target value is based on the input name. For example if you have an input whose name is user[first_name], you will get "_target" => ["user", "first_name"] in your handle_event params.

I presume it is safe to use.

Yes this is the point of _target so feel free to use it :slight_smile:

We prefix with underscore as to not clobber a user’s attribute.

1 Like

Thanks Matthieu and Chris. I’ll go ahead and use it.

cheers

Dave