0

I'm reviewing my code wrote time ago. The input text that I wrote is the following:

<input type="text" class="form-control form-control-sm" id="mypid" name="mypid" value="" placeholder="" readonly="readonly" required>

I tested the form and with my surprise I found out that even if I added 'required', I can actually submit even if the field is empty. The field is readonly because my code will autofill that field automatically, I need that the user doesn't write anything by themselves, so I need it to be readonly and required at the same time. But I didn't expect to see that now it's not considered required anymore. What am I doing wrong here? Any suggestion? Thank you very much for your help.

Elliot

elliot
  • 13
  • 4

1 Answers1

0

your question has already been answered here. But to explain it to you, you have to replace your readonly by onkeypress="return false;" which gives almost the same result.

  • 1
    Thanks for answering. I used your solution, but I also needed to add: autocomplete="off" in the input field, and color: transparent; text-shadow: 0 0 0 #000; in the CSS for this field. Now is perfect! – elliot Jan 04 '23 at 18:41