The empty check should include line break removal. Have a look at the etherpad widget for an example