javascript - Extjs checkbox and textarea - how to disable the checkbox on scroll behavior of the textarea?
问题描述
I have a text area that displays some text with a vertical scroll bar on the right and a checkbox below the text area as in the code below:
xtype: 'container',
items: [{
{
xtype: 'textarea',
scrollY: true,
screenX: true,
height: 130,
minHeight: 80,
top: 10,
width: 650,
id: 'testDisplay',
name: 'testDisplay',
itemId: 'testDisplay',
bind: {
value: some text
},
listeners: {
afterrender: function(cmp) {
textAreaComp = me.down('#testDisplay');
textAreaComp.setValue(someInfo);
}
},
},
{
xtype: 'checkboxfield',
name: 'testDisplayChkbox',
id: 'testDisplayChkbox',
itemId: 'testDisplayChkbox',
checked: false,
boxLabel: someLabel,
}
}]
I am looking to disable the checkbox at first and then enable it after scrolling to the end of the text area located above the checkbox. How can this be achieved?
解决方案
There is no built-in listener in ExtJS for this. You have to lookup the textarea in DOM and attach an onscroll
event. Then you can check whether scrolling reached the bottom and enable your checkbox.
Try the following code and also look at this fiddle:
Ext.create({
renderTo: Ext.getBody(),
xtype: 'container',
items: [{
xtype: 'textareafield',
value: 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?',
afterRender: function () {
// get checkbox
const myCheckBox = this.up('container').getComponent('myCheckBox');
// add onscroll listener to textarea
this.el.down('textarea').dom.onscroll = function () {
// check if scrolling reached bottom
if (this.scrollHeight <= (this.scrollTop + this.offsetHeight)) {
myCheckBox.setDisabled(false);
}
};
}
}, {
xtype: 'checkboxfield',
itemId: 'myCheckBox',
label: 'Lorem ipsum',
checked: false,
disabled: true
}]
});
推荐阅读
- r - 在 reactive() 函数中对数据集的一列进行子集化
- opencv - 你需要在你的机器上安装 Darknet 才能在 openCV 中使用 YOLOv4 权重和 .cfg
- arduino - lcd.setPWM(color, i) 在 ARDUINO 中有什么作用?
- caching - 使用 NewRelic 自定义缓存命中
- react-native - How to make an automatic increase in the width of the text input field depending on the number of lines?
- javascript - 如何在服务人员中获取我的配置 json 文件
- database-design - 规范化这个数据库结构
- ruby-on-rails - 如何在rails中制作重定向按钮
- wordpress - Open Site Shell 不适用于 Linux 上的 Local by Flywheel
- python - 使用 word2vec 和 gensim 查找相似词,抛出错误