xamarin forms webview.eval return type is voide . How to retrieve user input data? - xamarin

I am working on xamarin.forms. I have a content page which contains one webview which load 3rd party url(www.xyz.com) site and one button in shell.
On button click event I am trying to get user input data using
webview.eval(javascript: var data = document.getElementById('first-name').value;alert(data)).
It works fine but due to void return type I could not store data in local variable and I have a customrender(webviewrender) but don't know on shell button click event how can I get userinput data from webview
Please suggest me how do I achieve this functionality.I do not want XLab-Hybridwebview.

You'll probably need to have the JavaScript code call out to the external code when the result is available. You could then wrap that whole process in a TaskCompletionSource to make everything nice and easy to use.

Related

Xamarin.Forms Accessibilty VoiceReader

Quick question.
When it comes to Xamarin Forms, I noticed that if there is an alert called from the ViewModel
e.g:
DisplayAlertAsync("Title","Message", "Ok");
That the voice assistant only auto reads the first parameter of DisplayAlertAsync ("title") and does not auto-advance to the following parameters.
So, a temporary solution I did was concatenate the 1st and 2nd parameters into the 2nd parameter, so that VoiceReader auto reads both the title and message for accessibility users.
e.g:
DisplayAlertAsync("" ,"Title"+ "\n"+ Message", "Ok");
Is there a way to keep the traditional DisplayAlertAsync("Title","Message", "Ok"); parameter assignment, and have VoiceReader auto advance to the following parameters?
What you are looking at is expected behavior. Since Xamarin Forms uses Native APIs, so the alert dialog in the native platforms also does the same thing- Whenever you open a new page/alert, it should read the Title of that view.
For the most part, what you want to keep an eye out for is images & icons, you have to override the description of those items.
Q. Is there a way to keep the traditional DisplayAlertAsync("Title","Message", "Ok"); parameter assignment, and have VoiceOver/TalkBack auto advance to the following parameters?
A. No there isn't, you would have to create your own custom renderer if you want the reader to read everything.

Firefox Add-on SDK context-menu communicate with a content script loaded by page-mod

I'm creating a Firefox add-on with the Firefox Add-on SDK. This add-on does two things:
Inject a content script into every page with sdk/page-mod.
Add a context menu item using sdk/context-menu.
I want that when user clicks the context menu item, the add-on will call functions in the content script which was loaded by PageMod().
Unless your page-mod script is doing other things, it sounds like it might be more appropriate to load it using the context-menu contentScript or contentScriptFile properties. Alternately, load the portions of it that are needed by the context menu using this methodology. How best to split the script you are using depends on what you are actually doing. Without more information from you it is difficult to provide specific recommendations.
Communicating between content scripts loaded at different times or by different methods:
There is no method of directly doing what you desire. Content scripts that are not loaded at the same time by the same methodology are loaded into different contexts. They are unable to directly call functions between them. Multiple content scripts which are loaded at the same time and the same methodology share the same context/scope and can directly call functions between them.
However, you can communicate between content scripts. If they are not loaded into the same page, then you will need to communicate from one content script to another by using your main add-on script to first receive a message from one content script. Then, your main add-on script will need to send a second message (potentially containing exactly the same data) to the second content script. In other words, your main add-on code would need to relay the message between the two content scripts.
For content scripts that are loaded into the same page via different methods (e.g. one with page-mod and another as a context menu item – the situation in which you are interested), you can communicate directly between them using the DOM postMessage() API or a CustomEvent. Either can be used to send whatever JSON serializable data you desire between the two scripts. The DOM postMessage() API provides for more security, but is a bit more complex. With it you must also filter out any other "message" events that are sent on it by random code. It should probably be used if you are going to have code in a released add-on execute functions based on the content of the messages. This is a security issue which will depend on exactly what you are doing with the messages.
Example:
The following code will load a page-mod script into every page that matches "*.mozilla.org". It also creates a context menu item in those same pages which is displayed on links. Clicking on the context menu item will send an event from the context-menu content script with data containing the URL for which the context menu was displayed. The custom event will be received by the page-mod script. The page-mod script will then issue an alert with the URL for the link.
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*.mozilla.org",
contentScript: 'function contextMenuAlert(href) {'
+ ' window.alert("The context menu click on a link with URL:\\n" + href);'
+ '};'
+ 'window.addEventListener("myAddonId-contextMenu-clicked",'
+ ' function(event){contextMenuAlert(event.detail);});'
});
//Context menu
let cm = require("sdk/context-menu");
cm.Item({
label: "Alert link URL",
context: [
cm.URLContext(["*.mozilla.org"]),
cm.SelectorContext("a[href]")
],
contentScript: 'self.on("click", function (node, data) {'
+ ' var event = new CustomEvent("myAddonId-contextMenu-clicked",'
+ ' {detail:node.href});'
+ ' window.dispatchEvent(event);'
+ '});'
});
The above code produces a context menu that looks like:
When clicked on, the page-mod added content script initiates the following alert:
Using the message sent to choose from multiple different functions:
The information passed through the event can be expanded to allow multiple different functions to be called depending on the content. One method of doing this is to send an object as the message. One property of the object can be the function desired and another can be data to use in that function. My answers to the following questions contain examples of doing this:
Add menu item created with the sdk/context-menu API to the top of the context menu: This answer has code which uses the same passed message to indicate that either a click was made on a context menu item and pass the URL on which the context menu item was clicked, or to tell the main script that the context menu is about to be displayed so it can be modified.
How to console.log from ChromeWorker (alternative to dump): This answer shows sending a message that will result in a call to one of a variety of different functions and pass data to the function which was called. It was implemented as a way of using console methods from a worker with just console.log("message"). I'd code this one a bit differently were I doing it today, but it works and demonstrates the concept.
Because the documentation on MDN (here and here) was not very clear on content script to content script communication, I have updated the pages I found on which it was discussed. I have also added the above code as an example.

iTextSharp multiple actions for pushbuttonfield

In a PDF, I can set up a button to
Submit the FDF data to my RestAPI
Redirect to a webpage (to tell user 'Thanks') and that works perfectly.
But I need to do this using code... I am using iTextSharp in the following way:
pb is my pushbutton...
sURL is the URL I need the data to go to...
This is my code:
PdfFormField pff = pb.Field;
pff.SetAdditionalActions(PdfName.A, PdfAction.CreateSubmitForm(sURL, null, PdfAction.SUBMIT_XFDF));
af.ReplacePushbuttonField("submit", pff);
This does replace the button with the submit action. How do I keep the page redirect or how do I set it in code?
I have also tried PdfName.AA and PdfName.U based on examples and I am not certain what the different names are for. But nothing works. :-/
Apparently, the SetAdditionalActions() replaces the existing actions.
I have also tried using annotations and just adding a button that doesn't exist.
You are looking for a concept called chained actions as demonstrated in the PrintTimeTable example:
Chunk chunk = new Chunk("print this page");
PdfAction action = PdfAction.javaScript(
"app.alert('Think before you print!');", stamper.getWriter());
action.next(PdfAction.javaScript(
"printCurrentPage(this.pageNum);", stamper.getWriter()));
action.next(new PdfAction("http://www.panda.org/savepaper/"));
chunk.setAction(action);
In this case, we have an action that shows an alert, prints a page and redirects to an URL. These actions are chained to each other using the next() method.
In C#, this would be:
Chunk chunk = new Chunk("print this page");
PdfAction action = PdfAction.JavaScript("app.alert('Think before you print!');", stamper.Writer);
action.Next(PdfAction.JavaScript("printCurrentPage(this.pageNum);", stamper.Writer));
action.Next(new PdfAction("http://www.panda.org/savepaper/"));
chunk.SetAction(action);
See also the C# port of the book examples.

My Asp.Net Form data is not being submitted properly by Selenium 2 (Webdriver)

So I have written a test which populates a form, saves (in the admin tool), and then publishes.
However, my form is being lost between the save click and the publish click. I would show what the form looks like in HTML, but its pretty huge (like 20-30 fields)
In psuedo code, filling out the form looks like this:
1) Fill in form using dropdowns
2) Hit the save button - saves all form data
3) Hit the publish button
When I pause the script to see what is happening within selenium, I see the form properly being populated. I then see the Save button properly being clicked. When I pause the screen before hitting publish, I see that the content I have saved after clicking the save button was lost or is in the wrong fields.
When I do this manually, it works correctly. I know selenium submits forms differently than the standard user, however, is there anything I can do on my end to make sure that form is being submitted properly?
What does the Save button actually do? Is it Javascript, or a simple ` button?
Are you using the C# interface to Selenium webdriver? You probably have code that looks something like this:
FillInForm();
selenium.click(By.CssSelector("input[value='Save']"));
selenium.click(By.CssSelector("input[value='Publish']"));
Have you tried inserting, between save and publish, lines like the following:
// further up: By saveButton = ...
// By formField = ...
selenium.click(saveButton);
var formField = selenium.FindElement(formField);
Assert.That(formField.GetAttribute("value")
.contains("The text you typed into the form")
);
The point here being to check that save really is doing what it says on the tin. Generally, when you ask the WebDriver to "click" on a button, it does do exactly (more or less) what the user does. Alternatively, you can inject some javascript to force the form to submit - but then you're explicitly not testing what the user actually does (but you might find it's closer to what you experience).

CodeIgniter jQueryUI dialog form example

I am trying to use CodeIgniter and jQuery-ui dialog to create a modal window with form to update user information.
The process should be like:
1. Press a button on a view page.
2. A modal window pops up.
3. Inside the window is a form that a user can fill.
4. If the user filled something before, the information should be shown in corresponding field
5. Click the update button on the modal window to save the changes to database.
Can anyone provide a good sample of this process?
I used ajax to pass the data but it didn't work when I was trying to update the data to the database. It would be nice if an example of how to pass data from ajax to php and how php handle that.
Thanks,
Milo
well the jquery bit for post(), get(), ajax() works the same in any measure you would normally use it.. key difference here is with CI you can't post directly to a file-name file-location due to how it handles the URI requests. That said your post URL would be the similar to how you would access a view file normally otherwise
ie: /viewName/functionName (how you've done it with controllers to view all along. post, get, ajax doesnt have to end in a extension. I wish I had a better example then this but I can't seem to find one at the moment..
url = '/home/specialFunction';
jQuery.get(url, function(data) {
jQuery("#div2display").html(data);
});
in the case of the above you notice despite it not being a great example that. you have the url with 2 parameters home and specialFunction
home in this case is the controller file for home in the control folder for the home file in views the specialFunction is a "public function" within the class that makes the home controller file. similar to that of index() but a separate function all together. Best way I have found to handle it is through .post() and a callback output expected in JSON cause you can form an array of data on the php side json_encode it and echo out that json_encode and then work with that like you would any JSON output. or if your just expecting a sinlge output and not multiples echoing it out is fine but enough of the end run output thats for you to decide with what your comfortable doing currently. Hopefully all around though this gives you some clairity and hopefully it works out for you.

Resources