I have a select field:
<select class="form-control" data-admin--reports-form-target="sendFrequencySelect" name="automated_digest_task[send_frequency]" id="automated_digest_task_send_frequency"><option value="86400">1 day</option>
<option value="259200">3 days</option>
<option value="604800">7 days</option>
<option value="1209600">14 days</option>
<option value="2629746">1 month</option>
<option value="7889238">3 months</option>
<option value="15778476">6 months</option>
<option value="31556952">1 year</option></select>
...which I am setting to readonly via JS (I use Stimulus):
this.sendFrequencySelectTarget.readOnly = true;
I want to use readonly instead of disabled because disabled causes the select to not be submitted with a form, and I want it submitted.
Setting to readonly does indeed make the field readonly, but it doesn't cause the select to appear any different.
What I want is the field to be readonly, but its appearance to be that of a disabled select. That is, the background color dims to a gray and the cursor changes to not-allowed
on mouseover.
I have tried applying styles to selectors like select[readonly]
, select:read-only
, select[readonly="readonly"]
, input[type="select"]:read-only
, but none of these selectors seem to work.
For example...
select[readonly] {
cursor: not-allowed;
}
... has no effect.
How can I style readonly selects to appear disabled?