How to Find Reference to Dynamically Added Xamarin.Forms Element - xamarin

In Xamarin.Forms we want to add a new button using
f001content = new Xamarin.Forms.AbsoluteLayout;
f001content.Children.Add(new Button
{
Text = "Button",
AutomationId = "MyButton",
}, new Rectangle(0,0,100,40));
How can we find the reference to the button just added so that we can modify it in the future?

Create a reference to it
f001content = new Xamarin.Forms.AbsoluteLayout;
var btn = new Button
{
Text = "Button",
AutomationId = "MyButton",
}, new Rectangle(0,0,100,40));
f001content.Children.Add(btn);
If you need to reference it outside the scope it’s created in, you’ll need to declare it at the class level

If you're doing in the code behind, you need to create a variable to hold it.
var coolButton = new Button { Text = "Button", AutomationId = "MyButton" };
f001content.Children.Add(coolButton, new Rectangle(0,0,100,40));
Now when you need to reference it, you can. Note that you'll most likely want coolButton to be class wide or something. If you declare it in a method, you'll lose the reference when you exit the method.

Related

how do I add an item to mobiscroll at runtime

I have a mobiscroll list. I added an extra button called "Add new" I want to click that button and add a new item to the mobiscroll list.
Is that possible? I've been digging through that api to no avail. I can catch the event with a custom handler and I have the mobiscroll instance available there but no way to add to it.
If so, can I add that new item as custom html? I'm thinking an input so that the user can change that newly added item.
Thanks
The "pretty" way:
/*Create the new item*/
var newOption = document.createElement("option");
newOption.value = "My Value"
newOption.innerHTML = "My Text"
/*Append the new item*/
HTMLSelectControlID.appendChild(newOption)
/*Recreate the list*/
$("#HTMLSelectControlID").scroller('destroy').scroller($.extend(scrollerConfig["select"], { }));
The "dirty" way:
/*Inject the new item*/
HTMLSelectControlID.innerHTML += "<option value='My Value'>My Text</option>"
/*Recreate the list*/
$("#HTMLSelectControlID").scroller('destroy').scroller($.extend(scrollerConfig["select"], { }));

How to prepend items in kendo mobile ui at listview. I am using kendo v2013.1.319

I have try this
$("#divPostList").data("kendoMobileListView").prepend("...");
but it gives error prepend: prepend is not a function
prepend method has an array as argument. You should use:
$("#divPostList").data("kendoMobileListView").prepend([ "..." ]);
But this is not available in v2013.1.319, Can you use the latest release? If you need to stay on v2013.1.319 you need to do something like:
// Get reference to the listview
var listview = $("#divPostList").data("kendoMobileListView");
// Get reference to the datasource
var ds = listview.dataSource;
// Get original data
var old = ds.data();
// New items + old
var prepended = $.merge([ "Prepended 1", "Prepended 2" ], old);
// Send prepended to listview
ds.data(prepended);
You can see it running here : http://dojo.telerik.com/#OnaBai/ONiY
But of course, upgrading Kendo UI version makes it much easier.

How to change the label of widget(Firefox Add-on SDK)

I want to change the label of a widget when user click it, then I write the code looks like this:
var widgets = require("sdk/widget");
var statusBar = widgets.Widget({
id: "patchouliStatus",
label: "Wait Page Loading...",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function(){
this.contentURL = "http://www.google.com/favicon.ico";
this.label = "Clicked";
}
});
When I click the widget, the icon has changed, but nothing happen to the label.I move the mouse to the widget and it still show "Wait Page Loading...".Is there a way to dynamically change the label?
Firefox: v27.0.1
Add-on SDK: v1.15
Widget's label is read-only. You must use tooltip attribute to show the user a text on mouse hover, this way:
var widgets = require("sdk/widget");
var statusBar = widgets.Widget({
id: "patchouliStatus",
label: "Wait Page Loading...",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function(){
this.contentURL = "http://www.google.com/favicon.ico";
this.tooltip = "Clicked";
}
});
As docs says somewhere in this section -I think it could be more clearly documented-, tooltip value is an "optional text to show when the user's mouse hovers over the widget. If not given, the label is used". Also, examples in that section don't make it clear enough as I think they should.
Ok man thanks for the XPI, change changeLabel function to this, my above was really bugged.
function changeLabel(str){
var DOMWindows = Services.wm.getEnumerator('navigator:browser');
while (DOMWindows.hasMoreElements()) {
var aDOMWindow = DOMWindows.getNext();
var myWidget = aDOMWindow.document.getElementById('widget:jid1-njALX8gXKY872g#jetpack-patchouliStatus');
if (myWidget) {
Services.appShell.hiddenDOMWindow.console.info('myWidget:', myWidget);
myWidget.setAttribute('label', str);
myWidget.setAttribute('tooltiptext', 'tooltip changed');
} else {
Services.appShell.hiddenDOMWindow.console.info('myWidget null:', myWidget);
}
}
}
It also seems that the id of your widget starts with tyour addon id name.
Now I gave you the enumerator function because that goes over all windows and you can add event listener. But really if you just want to target the one that was clicked just get the most recent window, as that will obviously hold the correct window with your widget as we just clicked there and the event listener fires on click.
Change changeLabel to this:
function changeLabel(str){
var aDOMWindow = Services.wm.getMostRecentWindow('navigator:browser');
var myWidget = aDOMWindow.document.getElementById('widget:jid1-njALX8gXKY872g#jetpack-patchouliStatus');
if (myWidget) {
Services.appShell.hiddenDOMWindow.console.info('myWidget:', myWidget);
myWidget.setAttribute('label', str);
myWidget.setAttribute('tooltiptext', 'tooltip changed');
} else {
Services.appShell.hiddenDOMWindow.console.info('myWidget null:', myWidget);
}
}
Also that Services.appShell.hiddenDOMWindow.console.info is just something nice to debug, I left it in there so you can see how it works. It logs to "Browser Console" (Ctrl+Shift+J).
As a final note I used a non-sdk solution by requiring chrome. they advise you not to do that because they want you to use the SDK functions I don't know about SDK but you can use the getEnumerator and recentWindow function by requiring window/utils it looks like:
Read window/utils article here
I'll give you non-sdk solution here but someone will have to help convert it to sdk solution. You can paste this in your code it will work though.
Im not sure how the element is inserted into the dom but I guessed.
var {Cu, Ci} = require('chrome'); //if you want to paste this into scratchpad with with Environemnt set to Browser than dont need this line, this line is for sdk
var DOMWindows = Services.wm.getWindowEnumerator(null);
while (DOMWindows.hasMoreElements()) {
var aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
var myWidget = aDOMWindow.querySelector('#patchouliStatus'); //im not exactly sure how the element is inserted in the dom but im guessing here
if (myWidget) {
myWidget.label = 'rawr';
}
}

CKEditor editor instance .lang is undefined?

Hi I am trying to make some changes to our implementation of CKEDITOR 3.6.2
by removing all but 2 options in the link target type dropdown that appears in the link dialog's target tab.
I tried to achieve this using the API but I am getting an error in the minified core ckeditor.js file in the dialog() method on this line X=S.lang.dir; where S is the editor.
The .lang property of the editor instance is undefined when doing CKEDITOR.dialog(editor, 'link'), when viewing debugging the "editor" object I don't see a lang object anywhere, so I'm not sure why this is missing? I didn't work on our original implementation but as far as I know we have only added 2 plugins and not changed the ckeditor core.
Here is my code:
for (var i in CKEDITOR.instances) {
var editor = CKEDITOR.instances[i];
var dialogObj = CKEDITOR.dialog(editor, 'link');
var linkDialogTargetField = dialogObj.getContentElement('target', 'linkTargetType');
// API didn't seem to have a more efficient approach than clearing all and re-adding the one we want
linkDialogTargetField.clear();
linkDialogTargetField.add('notSet', '<not set>');
linkDialogTargetField.add('_blank', 'New Window (_blank)');
}
I have managed to make my change without using the API properly by doing the below:
CKEDITOR.on('dialogDefinition', function (ev) {
// Take the dialog name and its definition from the event
// data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
// Check if the definition is from the dialog we're
// interested on (the "Link" dialog).
if (dialogName == 'link') {
// Get a reference to the "Link target" tab.
var targetTab = dialogDefinition.getContents('target');
var targetField = targetTab.get('linkTargetType');
// removing everything except the 1st (none set) & 3rd (new window) options from the dropdown
targetField['items'].splice(1, 2);
targetField['items'].splice(2, 3); // the array is reduced by splice, so we have to splice from [2] onwards not from [4]
}
});
but I don't like this approach, does anyone have any ideas? or other ways to achieve the same result using the API?
Using second approach and overwritten the dropdown items instead of splicing.

Using Javascriptspellcheck with Ckeditor - Can't Name CKEditor Textarea id

I am updating some legacy code to support CKEditor up from FCKEditor, in classic asp. I am not a classic asp designer by trade so I am flying by the seat of my pants here. We previously used Javascriptspellcheck to to the spell checking. The problem I am having relates to this old code:
function doSpellCheck() {
var oSpell = new JavaScriptSpellCheck();
oSpell.callBack = function() {
oEditor.SetHTML($('POST_MESSAGE').value);
}
oEditor.UpdateLinkedField();
oSpell.spellCheckWindow('POST_MESSAGE');
}
oEditor is an instance of FCKEditor defined in a fckeditor_oncomplete() function. The new code I am trying to use is as follows:
function doSpellCheck() {
oSpellEditor = CKEDITOR.instances['POST_MESSAGE'].getData();
var oSpell = new JavaScriptSpellCheck();
oSpell.callBack = function() {
CKEDITOR.instances['POST_MESSAGE'].Setdata(oSpellEditor);
}
oSpell.spellCheckWindow('POST_MESSAGE');
}
The problem I seem to be facing is that JavaScriptSpellCheck(); needs the textarea id of the ckeditor instance. I attempted to follow the directions in This Post and nemisj's answer but I am having trouble with the code. I am not really understanding the DOM or how to manipulate it in this case. I know that this is not asp, to create the ckeditor instance I am using a custom asp sub to create it, but this is the area that I am having trouble with.
*EDIT: Found the answer. Where I am creating new CKEditor I needed to add text area attributes like so:
Set pageEditorTop = New CKEditor
' Change default textarea attributes
set textareaAttributes = CreateObject("Scripting.Dictionary")
textareaAttributes.Add "id", "POST_MESSAGE"
Set pageEditorTop.textareaAttributes = textareaAttributes
That code that you are trying to use doesn't make sense.
This is a straight port of the original code to CKEditor:
function doSpellCheck() {
var oEditor = CKEDITOR.instances['POST_MESSAGE'];
var oSpell = new JavaScriptSpellCheck();
oSpell.callBack = function() {
oEditor.setData($('POST_MESSAGE').value);
}
oEditor.updateElement();
oSpell.spellCheckWindow('POST_MESSAGE');
}

Resources