Correctly handle selected and active for generateFormElements