Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read-only date field on IOS browser?

Readonly fields don't seem to work on iOS. This is what I have:

@Html.EditorFor(model => model.DateOfBirth, new { htmlAttributes = new { @readonly = "true" } })

Essentially, this gets translated to this:

<input type="date" readonly="readonly" />

Works on Windows Chrome, but does does not work on the iPhone. Still able to edit the field. The date picker shows up.

like image 984
Prabhu Avatar asked Mar 24 '26 00:03

Prabhu


1 Answers

This is actually a bug in iOS, a readonly date field is still changeable.

You can fix it by adding something like this to the HTML:

onclick="this.blur()"
like image 171
Jan M Avatar answered Mar 25 '26 15:03

Jan M