2

i use label + hidden input.file for customize CSS style.

But when i add a required attribute , it does not work.

In console log: An invalid form control with name='imageFile' is not focusable..

Is there anyway to fix this without JavaScript ?

<div>
  <label for="imageFile" class="button">Image</label>
  <input type="file" required id="imageFile" name="imageFile" style="display:none" />
</div>
G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
padavan
  • 714
  • 8
  • 22

2 Answers2

0

Remove required because the display is none. The user can't modify the value of the input if it not displayed, so why it will be required.

gabida
  • 170
  • 7
0

I found 'hack' solution , thx @G-Cyrillus.

[type='file'] {
    opacity: 0;
    position: absolute;
    width: 0;
    left: 0;
}

Required alert work fine.

enter image description here

padavan
  • 714
  • 8
  • 22