You only need #name
if the form array keys don't provide a unique path for form_state. I agree with @Jaypan, I too found setting #name
never really necessary, it seems to be more reliable to define a unique key to the lowest level of the form element if you have issues with Ajax not finding the form element. In either case, #name
or form key, it has to be predictable, derived from data which doesn't change between form builds, for example a field delta.
The form object and $form_state are not cached when a form is rendered, only after submitting the first Ajax request. So it doesn't help to store data in $form_state you want to use to rebuild $form.