In extjs4 How to catch textarea's keypress event in controller - event-handling

i am working in extjs. i have one textarea to enter word and one search button.I have view as-
Ext.define('Balaee.view.kp.Word.Word', {
extend : 'Ext.form.Panel',
id : 'WordId',
alias : 'widget.Word',
title : 'Dictionary',
height : 500,
items : [{
xtype : 'textfield',
fieldLabel : 'Enter the word',
name : 'wordtext',
//anchor:'100%',
allowBlank : false,
emptyText : 'Enter the word',
enableKeyEvents : true,
id : 'wordtext',
action : 'EnterAction'
},
{
xtype : 'button',
formBind : true,
fieldLabel : 'Search',
action : 'SearchAction',
text : 'Search'
}
]
});
And in controller i have function as-
SearchWord:function(button)
{
var j = Ext.getCmp('wordtext').getValue();
console.log("word is:"+j);
var answers = '{"data":[';
answers = answers + '{"word":"'+j+'"}'
answers =answers+']}';
console.log(answers);
var storeObject=this.getStore('kp.WordStore');
storeObject.load({
params:{
data: answers
},
callback: function(records,operation,success){
//console.log(records)
},
scope:this
});
var temp=Ext.getCmp('WordId');
temp.remove('WordInfoId');
var details=Ext.create('Balaee.view.kp.Word.WordInfo');
//details.region='center';
temp.add(details);
}
});
Now above function is working correctly when user is entering word in textarea and clicking on submit button. But i want to execute above "SearchWord" function of controller on enter button click also. i.e. If user will enter word in textarea and will press enter key then same function of controller needs to be executed.So how to catch textarea's enter key press event in controller?

Just listen for the specialKey event and call your function if the key is ENTER.
So in your controller's init function, do something like this:
this.control({
'#wordtext':{
specialkey: function(field, e){
if (e.getKey() == e.ENTER) {
//Do whatever you want here (such as call your SearchWord function)
}
}
}
});

Related

jsTree component background menu?

In jsTree component available a ContextMenu plugin.
But it's available only when user clicked on specific node.
I need to add context menu by clicking on component's background (to add root nodes, for example).
Is it possible to attach a context menu plugin for background ?
Yes you can, but you need to define all actions you need to be available, as the defaults are related to a node, so they won't work (rename, delete, etc).
This will show a menu when the tree container is clicked and will show an option to create a root node:
$('#tree').on('contextmenu.jstree', function (e) {
e.preventDefault();
if($(e.target).is('#tree')) {
$(document).one("context_show.vakata.jstree", $.proxy(function (e, data) {
var cls = 'jstree-contextmenu jstree-default-contextmenu';
$(data.element).addClass(cls);
}, this));
$.vakata.context.show($(this), { 'x' : e.pageX, 'y' : e.pageY }, {
"create" : {
"separator_before" : false,
"separator_after" : false,
"_disabled" : false,
"label" : "Create",
"action" : function (data) {
var inst = $.jstree.reference(e.target);
inst.create_node(null, {}, "last", function (new_node) {
setTimeout(function () { inst.edit(new_node); },0);
});
}
}
});
}
});

How to add ColumnListItem to a table inside a page in MVC from other page controller

I have a SAPUI5 application written in MVC
I have a view called oPage4:
var landscapePage = new sap.m.Page({
title : "Landscape Name",
showNavButton : true,
navButtonPress : [oController.back,oController],
footer : new sap.m.Bar({
id : 'landscapePage_footer',
contentMiddle : [
new sap.m.Button({
}),
new sap.m.Button({
})
]
}),
});
oLandscapePageTable = new sap.m.Table("landscape", {
inset : true,
visible : true,
getIncludeItemInSelection : true,
showNoData : false,
columns : [ new sap.m.Column({
styleClass : "name",
hAlign : "Left",
header : new sap.m.Label({
})
}) ]
});
landscapePage.addContent(oLandscapePageTable);
return landscapePage;
then inside page1 controller I want to add a columnlistitem to the table of page 4.
var oPage4 = sap.ui.getCore().byId("p4");
var landscapePageRow = new sap.m.ColumnListItem({
type : "Active",
visible : true,
selected : true,
cells : [ new sap.m.Label({
text : something
}) ]
});
oPage4.getContent().addItem(landscapePageRow);
it doesn't work. please show me how to do so?
Ok, I think I understood your problem now. In general I would avoid calling the page and doing manipulations on it from another view. However, it is absolutely possible:
Additional functions in your view
You can extend your page4 with some more functions that can be called from outside like this:
sap.ui.jsview("my.page4", {
createContent : function() {
this.table = ...
...
},
addColumnListItem : function(columnListItem) {
// add it to the table calling this.table ...
}
}
From another view you´re now able to call this function like this:
var page4 = sap.ui.jsview("my.page4");
page4.addColumnListItem(page4, columnListItem);
Attention: The page4 object itself doesn´t point to the control you´re returning but to the the view instance itself. You will notice this, if you log the page4 object to the console. This is why you have to add functions like described.
Some other approaches would be to use the EventBus like described here to publish and subscribe to events. Since you´ve asked for it let me show you how you could do it:
Using the EventBus
The main intention is, that one can subscribe to a particular event and others can publish such events to the eventbus. Let me give you an example:
Subscribing to the EventBus:
var eventBus = sap.ui.getCore().getEventBus();
eventBus.subscribe("channel1", "event1", this.handleEvent1, this);
Of course you can name your channel and events as you wish. The third parameter indicates the function, that will be called in case of published events. The last paramter is the scope 'this' will point to in the given function.
Your handleEvent1 function could look like this:
handleEvent1 : function(channel, event, data) {
var listItem = data.listItem
}
Publishing events to the EventBus:
var columnListItem = ...
var eventBus = sap.ui.getCore().getEventBus();
eventBus.publish("channel1", "event1",
{
listItem : columnListItem
}
);
One more option you have is to make the columnListItems depending on a model. Like everytime it depends on your actual architecture and data.
Let me know if this solved your problem or if you need some more information.

Extjs3.3.0 numberfield

The window contain a form which including NumberField(allowBlank: false), as soon as you open the window the NumberField is outlined in red. saying the field is required. but we hope the NumberField should not be outlined in red unless the user clicks the filed and clicks away without entering anything. how to config this NumberField.
extjs library: 3.3.0
Here is what I do.
Basically I listen to 'focus'/'blur' event and if value is blank, call markInvalid, otherwise clearInvalid.
xtype : 'numberfield',
fieldLabel :'number',
markNumberInvalid : function(){
if(this.getValue() == ""){
this.markInvalid();
}else{
this.clearInvalid();
}
},
listeners : {
'focus' : function(){
this.markNumberInvalid();
},
'blur' : function(){
this.markNumberInvalid();
}
}

Kendo Grid in MVVM and translating or customizing command buttons

This is my MVVM Code and I have troubles customizing the text of Update/Cancel command buttons.
I have customized Edit/Delete buttons but what about the command buttons that are hidden for now and will be visible when I click on Edit button?
Please help me customizing such commands. How can I do that?
<div id="grid" data-role="grid" data-sortable="true" data-editable="inline" data-Scrollable="true"
data-toolbar='[{name:"create", text:"新しいドメインの追加"}]'
data-pageable="true" data-columns='[{field: "Domain", title: "ドメイン", width: 250, filterable: false, sortable: false},
{"command": [{name:"destroy",text:"削除"},
{name:"edit",text:"編集"}]}]'
data-bind="source: dataSource, events: { edit: edit, dataBound: dataBound }"></div>
Answering this question would help a lot of people who want to customize or translate Update Command or Cancel Command as well as Edit Command or Destroy Command.
If you want to customize the buttons update,cancel,delete,add,edit just do this
{
command : [{
name : "edit",
text : {// sets the text of the "Edit", "Update" and "Cancel" buttons
edit : "CustomEdit",
update : "CustomUpdate",
cancel : "CustomCancel"
},
}, {
name : "destroy",
text : "Destroy"
} // sets the text of the "Delete" button
]
Here is a fiddle
For localizing Update and Cancel buttons when you update on popup mode, you need to define the command as:
command: [
{
name: "edit",
text: { edit: "Edita", update: "Actualiza", cancel: "Cancela"}
},
{
name : "destroy",
text : "Borra"
}
],
EDIT: If you also want to change the title of the popup window, then you should add window.title to editable in the grid definition:
editable : {
mode : "popup",
window : {
title: "Edición",
}
},
If you want to take a look into an example: JSFiddle

Adding custom tag with TinyMCE using ed.selection.setContent

I'm trying to add a custom tag to content selected in the editor, but <title> content </title> does not work. This works though: [title] content [/title]
Googling leads me to believe that I need to use these lines as well, but it does not help:
extended_valid_elements : "title",
custom_elements: "title",
Example:
For some reason this code does not work:
setup : function(ed) {
// Add a custom button
ed.addButton('mybutton', {
title : 'My button',
'class' : 'Mybutton',
image : 'img/example.gif',
onclick : function() {
// Add you own code to execute something on click
ed.focus();
ed.selection.setContent("<title>" + ed.selection.getContent() + '</title>');
}
But this works:
setup : function(ed) {
// Add a custom button
ed.addButton('mybutton', {
title : 'My button',
'class' : 'Mybutton',
image : 'img/example.gif',
onclick : function() {
// Add you own code to execute something on click
ed.focus();
ed.selection.setContent("[title]" + ed.selection.getContent() + '[/title]');
}
This is the way to go
extended_valid_elements : "title",
custom_elements: "title",
You do not see anything because title is not defined elsewhere than in the head.
You will find your title-tag using firebug and it will hold what you expect to hold (ed.selection.getContent() wrapped into a title-tag.):