Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i read only value attr?

Tags:

javascript

I want make value attribute to read-only and i do these code but not work ??

Need help ?

const obj = {
  name: "karl"
}
const origName = obj.name;
Object.defineProperty(obj, 'name', {
  enumerable: false,
  configurable: false,
  get() {
    return origName + 2;
  }
});
like image 279
amin mahjoob Avatar asked Jan 27 '21 07:01

amin mahjoob


People also ask

How do I make an attribute read only?

Summary. If you need to make a read-only attribute in Python, you can turn your attribute into a property that delegates to an attribute with almost the same name, but with an underscore prefixed before the its name to note that it's private convention.

What attribute makes element read only?

The Boolean readonly attribute, when present, makes the element not mutable, meaning the user can not edit the control. If the readonly attribute is specified on an input element, because the user can not edit the input, the element does not participate in constraint validation.

How do you check if input field is read only?

Use the readOnly property to check if an element is read-only, e.g. if (element. readOnly) {} . The readOnly property returns true when the element is read-only, otherwise false is returned.


1 Answers

You must add "writebale" key; Like this;

 Object.defineProperty(obj, "name", {
        value: "karl",
        writable: false
    });
like image 135
Veysel Erdemci Avatar answered Sep 29 '22 11:09

Veysel Erdemci