Sets `required` attribute if set to true