fix bug with forms where data and ui have different hierarchies

and add tests

fixes: http://manage.dimagi.com/default.asp?117610
Whoops, good catch: https://github.com/dimagi/commcare-hq/pull/3607