•  


GitHub - corenzan/readonly.js: Make form controls - even <select> - read-only.
Skip to content

corenzan/readonly.js

Folders and files

Name Name
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Readonly.js

Make form controls - even <select> - read-only.

About

Readonly.js is a lightweight wrapper to fix the inconsistency of the readonly attribute in form controls. According to current specifications the attribute will be ignored in certain input types, and is completely void in <select> elements. This little helper aims to fix that. If you're curious to know more read the Web Standards section.

Upgrade to 3.x.x

If you're coming from older versions take note:

  • The control no longer gets a class added to it. You should use the attribute selector instead. e.g. select[readonly] { ... }
  • Now you can keep the actual control and its surrogate (formerly known as sham ) in sync by dispatching a change event on the element. .e.g input.dispatchEvent(new Event('change')) . This will make sure that changes to name and/or value made via JavaScript will take effect.

Compatibility

Version 3.0.0 was rewritten with a modern syntax but we're using Babel to transpile it into a more compatible JavaScript syntax wise. We also make use of some relatively newer browser APIs like querySelectorAll . Anything newer than IE11 should be fine but if you run into issues please submit an issue so we can look into it.

Usage

Only a single function is exported: readonly . e.g.

readonly
(
'input, select'
)
;

This will toggle the read-only state of matching elements.

The first argument can be either:

  • A selector.
  • A single element.
  • A collection of elements ( Array or NodeList ).

You can also force a state by passing an additional argument; true for read-only or false for editable .

readonly
(
'input, select'
,
 true
)
;

If you're using jQuery it'll be installed as a plugin.

$
(
'input, select'
)
.
readonly
(
true
)
;

Web Standards

Have you ever wondered why the readonly attribute doesn't work in <select> elements? Well, the whole thing is more complicated then one might think, but you can read all about it here: whatwg/html#2311 . You also could help advance the web standards by leaving a comment with why such feature would be useful to you.

License

The MIT License ⓒ 2013 Arthur Corenzan. See LICENSE.md for full notice.

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본