Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use readonly attribute in <input> without changing the cursor

If I have an <input> field with the readonly attribute, it still appears with the I-beam text cursor. Is there a way to stop that cursor from showing?

I cant use the disabled attribute because request.getParameter() does not work on disabled fields.

like image 881
Premshankar Tiwari Avatar asked Jun 26 '13 11:06

Premshankar Tiwari


People also ask

How do I make input fields read only?

The readonly attribute of <input> element is used to specify that the input field is read-only.

Does readonly input get submitted?

A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit.

What is the difference between a readonly input and a disabled input?

When a textarea is disabled , it will be ignored by a parent form. However, when a textarea is readonly the contents of the textarea will still be submitted with the form even though the user cannot modify the contents.

How do I set readonly attributes?

Use setAttribute() Method to add the readonly attribute to the form input field using JavaScript. setAttribute() Method: This method adds the defined attribute to an element, and gives it the defined value. If the specified attribute already present, then the value is being set or changed.


2 Answers

The idea of readonly elements is that you can still read and copy the text, just not edit them. That said, you can change the cursor using CSS attribute selectors. This example will match any input element with a readonly attribute:

input[readonly] {      cursor: pointer; } 
like image 101
Olly Hodgson Avatar answered Sep 24 '22 00:09

Olly Hodgson


I did not want to override bootstrap's default styles so I came along with the following solution:

My LESS File:

input[readonly] {
    &.default-cursor {
        cursor: default;
    }
}

Or in CSS:

input[readonly].default-cursor {
    cursor: default;
}

My HTML:

<input type="text" class="form-control text-xl default-cursor" readonly>
like image 34
totas Avatar answered Sep 20 '22 00:09

totas