ExtJS 6 TextArea readOnly:如何在textarea中限制鼠标光标

时间:2017-06-29 08:43:00

标签: extjs cursor textarea mouse readonly

我有一个ExtJS6 textarea,它具有绑定变量readOnly

bind:{
readOnly : '{someCondition}'
}

当textarea具有readOnly:true时,单击文本字段鼠标光标位于文本区域内。我希望在只读取文本区域时限制鼠标光标。

使用“disabled”属性可以正常工作,并且不允许鼠标光标位于文本区域内,但不显示带文本区域的垂直滚动条。因此不能使用这个属性。

你能否提出一些解决方案。

2 个答案:

答案 0 :(得分:0)

您必须指定bind:{ readOnly : '{someCondition}' editable : false({somecondition}) } config

PS C:\Users\Dante\Desktop> django-admin startproject MyProject1
PS C:\Users\Dante\Desktop> cd .\MyProject1
PS C:\Users\Dante\Desktop\MyProject1> ls


    Directory: C:\Users\Dante\Desktop\MyProject1


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2017-06-29     12:17                .idea
d-----       2017-06-29     12:13                MyProject1
-a----       2017-06-29     12:13            830 manage.py


PS C:\Users\Dante\Desktop\MyProject1> python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    import django
ModuleNotFoundError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    "Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?
Did you forget to activate a virtual environment?
PS C:\Users\Dante\Desktop\MyProject1> python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    import django
ModuleNotFoundError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    "Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?
Did you forget to activate a virtual environment?

fiddle

答案 1 :(得分:0)

@Ronak Patel提供的answer中的小提琴似乎奏效了。如果您还想阻止用户使用鼠标选择文本区域中的文本,您可以将user-select设置为none。虽然这不是标准做法,但您也可以更改光标以向用户指示他们无法选择文本。 可以在writeableChange事件侦听器中进行这些更改:

writeableChange: function () {
                        if (this.readOnly) {
                            this.inputEl.dom.style.userSelect = 'none';
                            this.inputEl.dom.style.cursor = 'not-allowed';
                        } else {
                            this.inputEl.dom.style.userSelect = 'inherit';
                            this.inputEl.dom.style.cursor = 'inherit';
                        }
                    }

请参阅更新的小提琴here(使用复选框将textarea设为readOnly或不显示。)