Getting value of textfield and copy-paste to another textfield in protractor - getelementbyid

Please help me. The output of the code below is "[Obj obj".
it('LeanAsset-input,function(){
dv.sleep(5000);
var PONum = element(by.xpath('//*[#id="pordr-create-content"]/div[1]/div[1]/div[2]/input'));
PONum.getText().then(function (text) {
console.log(text);
});
element(by.xpath('//*[#id="pordr-create-content"]/div[1]/div[2]/div[2]/input')).clear().sendKeys(PONum);
}');

You are trying to pass the web element instead of text in sendKeys.
You can try below the two solutions:
it('LeanAsset-input,function(){
dv.sleep(5000);
var PONum = element(by.xpath('//*[#id="pordr-create-content"]/div[1]/div[1]/div[2]/input'));
var text = PONum.getText();
element(by.xpath('//*[#id="pordr-create-content"]/div[1]/div[2]/div[2]/input')).clear().sendKeys(text );
}');
or
it('LeanAsset-input,function(){
dv.sleep(5000);
var PONum = element(by.xpath('//*[#id="pordr-create-content"]/div[1]/div[1]/div[2]/input'));
PONum.getText().then(function (text) {
console.log(text);
element(by.xpath('//*[#id="pordr-create-content"]/div[1]/div[2]/div[2]/input')).clear().sendKeys(text);
});
}');

Related

Upload Image: Cannot read property 'setCustomData' of undefined

I am trying to embed into the editor an uploaded image. My filebrowserUploadUrl is /api/m/image and it seems to be working fine. After I clicked the Send it to the Server button, there is a script error as follows:
image.js?t=H4PG:19 Uncaught TypeError: Cannot read property 'setCustomData'
of undefined
at textInput.onChange (image.js?t=H4PG:19)
at textInput.n (ckeditor.js:10)
at textInput.CKEDITOR.event.CKEDITOR.event.fire (ckeditor.js:12)
at textInput.setValue (ckeditor.js:619)
at textInput.setValue (ckeditor.js:545)
at a.q (ckeditor.js:841)
at ckeditor.js:31
at Object.callFunction (ckeditor.js:31)
at image?CKEditor=editor&CKEditorFuncNum=1&langCode=en:1
The last line in the above is the call to filebrowserUploadUrl and the response from that is:
window.parent.CKEDITOR.tools.callFunction(1, '/images/bulletins.jpg', 'Uploaded successfully');
The Uploaded successfully message is shown in an alert. The Preview box under Image Info tab is not updated. But if I clicked OK to close the dialog, the image (bulletins.jpg) is embedded in the editor alright.
What could be causing the error and how do I fix it?
I found what was causing it. I wanted to set the default tab when the insert image dialog is launched to the Upload tab. I use the following code:
CKEDITOR.on("dialogDefinition", function(ev) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if (dialogName === "image") {
dialogDefinition.onShow = function() {
this.selectPage("Upload");
}
}
});
When the above code is used, that error happens when a file is uploaded.
I was having same issue, and after using proposed solution from vikram, editor was generating error while pasting image link into the text. Better approach here, not to completely override default onShow method, but add more to it in the following way:
CKEDITOR.on('dialogDefinition', function (ev) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if (dialogName == 'image') {
var oldOnShow = dialogDefinition.onShow;
var newOnShow = function () {
this.selectPage('Upload');
this.hidePage('Link');
// change tabs order
$('a[title=Upload].cke_dialog_tab').css('float', 'left');
};
dialogDefinition.onShow = function () {
oldOnShow.call(this, arguments);
newOnShow.call(this, arguments);
};
}
});
After debugging a lot I found a solution on this.
If you will see onChange method of txtUrl textBox in image.js
See line number 507 and 513
you will understand cause of this error.
at line 513 setCustomData is called.
original.setCustomData( 'isReady', 'false' );
CKEDITOR.on("dialogDefinition", function(ev) {
var dialogName = ev.data.name;
//current editor
var editor = ev.editor;
var dialogDefinition = ev.data.definition;
if (dialogName === "image") {
dialogDefinition.dialog.on('show', function(e){
var dialogBox = e.sender;
//This line is the answer of your question
//this line will get rid of the error setCustomData
dialogBox.originalElement = editor.getSelection().getStartElement();
this.selectPage("Upload");
});
}
});

Get values from selected CustomTile SAPUI5

I have a product catalog made with CustomTile Control. When I press one tile, I want to go to a details page. For that I need to know some of the values that are on the pressed tile, which I'm not able to.
Here is the code for the tile and the binding:
var sServiceUrl = "/sap/opu/odata/sap/ztestefardas_srv/"; //URL do serviço oDATA
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl);
sap.ui.getCore().setModel(oModel);
OData.read("/sap/opu/odata/sap/ztestefardas_srv/catalogo",
function (response){
for(var key in response.results) {
var value = response.results[key];
var oImg =new sap.ui.commons.Image({
width :"160px",
height :"160px"
}).setSrc(value["img"]);
oImg.addStyleClass("img_cat");
var oMatxt =new sap.ui.commons.TextView({
text: value["matxt"],
width: "200px"
}).addStyleClass("matxt");
var oAtr =new sap.ui.commons.TextView({
text: "Atribuídos: "+value["n_atr"],
width: "200px"
}).addStyleClass("second_line");
if (value["n_dis"] > 0){
var oDis =new sap.ui.commons.TextView({
text: "Disponíveis: "+value["n_dis"],
width: "200px"
}).addStyleClass("second_line_disp");
} else {
var oDis =new sap.ui.commons.TextView({
text: "Disponíveis: "+value["n_dis"],
width: "200px"
}).addStyleClass("second_line");
}
var oPtxt =new sap.ui.commons.TextView({
text: "Próximo levantamento:",
width: "200px"
}).addStyleClass("third_line");
var oPlev =new sap.ui.commons.TextView({
text: value["p_lev"],
width: "200px"
}).addStyleClass("third_line");
var oLayout = new sap.ui.commons.layout.VerticalLayout({
content: [oImg,oMatxt,oAtr,oDis,oPtxt,oPlev]
});
var oTile = new sap.m.CustomTile({
content:oLayout,
press: function(oEvento){
//missing code to get values from selected tile
oNavContainer.to(Page2);
}
}).addStyleClass('sapMTile');
oContainer.addTile(oTile);
}});
I've tried with the table attach row selection change way, but it's not working too.
Can you please help?
Thank you.
Add the following code in your function (response) method:
var valueModel = new sap.ui.model.json.JSONModel({
"Value": "##your value here##",
});
oLayout.setModel(valueModel);
Add the following code in the press function handler:
var oLayout = oEvento.getSource().getContent();
var value = oLayout .getModel().getProperty("/Value");
Then you can get values from the CustomTile by using data binding to get the value your want.
Hope it helps.
I found a way to make this work.
within the FOR that I used to read the data from the odata:
oTile.data("matnr", value["Matnr"]);
oTile.data("matxt", value["Itmfdx"]);
oTile.data("n_dis", value["n_dis"]);
oTile.data("n_atr", value["n_atr"]);
oTile.data("endda", value["Endda"]);
oTile.data("itmfd", value["Itmfd"]);
these value["xpto"] are the keys from the response results (OData.read("/sap/opu/odata/sap/zmm_fardamentos_srv/CatalogoSet?sap-ui-language=PT",
function (response){
for(var key in response.results) {
var value = response.results[key];)
Then, I created a function for the attachPress event of oTile with these:
oTile.attachPress( function(){
sap.ui.getCore().getControl("selimg").setSrc(this.data("img"));
sap.ui.getCore().getControl("bigpic").setSrc(this.data("img"));
sap.ui.getCore().getControl("nome_material").setText(this.data("matxt"));
sap.ui.getCore().getControl("itmfd_var").setText(this.data("itmfd"));
sap.ui.getCore().getControl("atr_det").setText(this.data("n_atr"));
sap.ui.getCore().getControl("disp_det").setText(this.data("n_dis"));
sap.ui.getCore().getControl("lev_data").setText(this.data("endda"));
the names within getControl are the id of the variables that will hold the values.
Maybe this is not the fanciest way, but it sure works :)

jQuery Isotope - Issue with multiple filters

I try to use multiple filters inside portfolio-like page which uses Isotope.js. Please take a look at this page: http://decart-design.com/avancia-wp/vi-tilbyr/. Single filter works fine but not multiple filters don't :( Here's a piece of JS code I use:
jQuery('.filtering li').on('click', 'a', function(e) {
e.preventDefault();
if ( jQuery(this).parent().hasClass('selected') ) {
return;
}
var filters = {},
optionSet = jQuery(this).parents('.option-set');
jQuery(this).parent().parent().find('li').removeClass('selected');
jQuery(this).parent().addClass('selected');
var group = optionSet.data('filter-group');
filters[group] = jQuery(this).data('filter');
var isoFilters = [];
for ( var prop in filters ) {
isoFilters.push( filters[prop] );
}
var selector = isoFilters.join('');
var portfolioItems = jQuery(this).parent().parent().parent().parent().find('.filterable-items');
portfolioItems.isotope({ filter: selector });
console.log(selector);
return false;
});
For some reason (I don't why) but isoFilters.push( filters[prop] ); just doesn't work. After I click a second filter the items array just replaced with new value instead of adding it to this array. As you can see in console it just replaced with new value instead of adding it to the array. It's so strange...
Here's a working example from author's website: http://isotope.metafizzy.co/demos/combination-filters.html.
Could please someone help me to figure out what I make wrong?
Thank you in advance! Hope someone can help me to solve this problem.
Best regards,
Alex
I've found a way to solve this issue. Here's a proper code:
jQuery('.filtering li').on('click', 'a', function(e) {
e.preventDefault();
if ( jQuery(this).parent().hasClass('selected') ) {
return;
}
jQuery(this).parent().parent().find('li').removeClass('selected');
jQuery(this).parent().addClass('selected');
var isoFilters = [];
var elems = jQuery(this).parents('.filter-wrap').find('li.selected a');
jQuery.each(elems, function(i, e){
isoFilters.push(jQuery(e).attr('data-filter'));
});
var selector = isoFilters.join('');
var portfolioItems = jQuery(this).parent().parent().parent().parent().find('.filterable-items');
portfolioItems.isotope({ filter: selector });
console.log(selector);
return false;
});
Hope this will help someone who stuck with similar problem.

Pass parameters to new window [Titanium]

In the following code, I need to pass the text variable from app.js to app_flip.js and display it over there. How can I do this ?
**In app.js**
var win = Titanium.UI.createWindow({backgroundColor:'white'});
button.addEventListener('click,function(e){
Ti.include('app_flip.js');
});
var text = Ti.UI.createLabel({ text:"hello" });
win.add(text);
**In app_flip.js**
var win = Titanium.UI.createWindow({backgroundColor:'white'});
You can open a new window using the following method
app.js
button.addEventListener('click', function(e){
var win = Ti.UI.createWindow({
url : 'app_flip.js',
backgroundColor : 'white',
_customProperty : 'Value of the property'
});
win.open();
});
app_flip.js
var win = Ti.UI.currentWindow;
var _customProperty = win._customProperty;
alert(_customProperty); //Will display Value of the property
You can use this as a reference

How to Fix Poor Performance on Filter By Text

A while back I found some code that allows you to filter the contents of a SELECT by typing in a text element. It works well however, over time the performance degrades pretty badly. I'm not sure if it is the filter code or the way in which I am activating it.
The SELECT shows up in a modal dialog (bootstrap) so I have the following code:
$('#myModal').on('shown', function () {
$(".focusable").val("").focus();
var select = $('#myModal').find(".modal-body").find("select");
var text = $('#myModal').find(".modal-body").find("input[type='text']");
select.filterByText(text, true);
});
And here is the filter code:
jQuery.fn.filterByText = function (textbox, selectSingleMatch) {
return this.each(function () {
var select = this;
var options = [];
$(select).find('option').each(function () {
options.push({value:$(this).val(), text:$(this).text(), data:$(this).data("short-name")});
});
$(select).data('options', options);
$(textbox).bind('change keyup', function () {
var options = $(select).empty().data('options');
var search = $.trim($(this).val());
var regex = new RegExp(search, 'gi');
$.each(options, function (i) {
var option = options[i];
if (option.text.match(regex) !== null) {
var copyOption = $('<option>').text(option.text).val(option.value);
copyOption.data("short-name", option.data);
$(select).append(copyOption);
}
});
if (selectSingleMatch === true &&
$(select).children().length === 1) {
$(select).children().get(0).selected = true;
}
});
});
};
Can anyone shed some light on where my performance issue(s) might be and how to solve it?
reading through the comments I would suggest to add the following:
$(textbox).bind('change keyup', function(event) {
console.log(event);
// your code
});
Is the event triggered more than once on a single keyup after some times the dialog is shown?
$('#myModal').on('hidden', function () {
$('#myModal').find(".modal-body").find("input[type='text']").off("change keyup");
});

Resources