Widget Communication: text input from user

556
5
Jump to solution
03-13-2012 07:46 AM
AndreaGrygo
New Contributor
Hello, I asked a similar question in the wrong (API) forum a while back, so am rephrasing after looking through other posts and making a bit of progress.

On Viewer load the splash screen and eSearch widgets are loaded. The user is prompted to enter their First Name, Last Name, and email into text boxes on the splash screen then click an OK button which closes the splash screen.
I'm trying to add these 3 fields (FirstName, LastName, email) to a URL to create a link that will subscribe the user to project updates.

If possible, I'd like to implement this in a popup window (PopUp or Info Template) and eSearch results.
I've been able to utilize the modified code from this thread (thank you Robert!) to have each project number become a clickable link in the eSearch results.

Is there way with Widget Communication to take the first name, last name, and email from the splash screen and incorporate those values into the URL string?
Ultimately the URL would be: http://webistehere/PW/WebForm2.aspx?FirstName=Joe&LastName=Mapper&email=jmapper@maps.com&ConstId=ProjectNumber
Where Joe, Mapper, and jmapper@maps.com are text fields entered on the splash screen and ProjectNumber is from an attribute field called PROJNUM

With my limited knowledge, I think the final link would look conceptually something like this (in PopUpRendererSkin.mxml of eSearch)..but I need help in figuring it out:
if (match && match.length > 0)                                     {                                         label = new mx.controls.Label();                                         htmlText = '<a href="' + match[1] + '" target="_blank">' + match[1] + "</a>";                                                                              } else if (match2 && match2.length > 0){                                         label = new mx.controls.Label();                                         htmlText = '<a href=" http://webistehere/PW/WebForm2.aspx?FirstName={firstName.text}&LastName={lastName.text}&email={email.text}&ConstId=PROJNUM" target="_blank">' + '<b>MP 116-1284</b>' +"</a>";                                      continued for all project numbers....


Thank you all kindly!!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Andrea,

   Taking the values from the splash screen and trying to feed them to the URL is quite a bit to late in the process to do anything with the URL. You could take the values from the splash screen and set them to some public vars in the application and then get them from the Application using FlexGlobals.topLevelApplication.yourPublicVar. So something more like this:

import mx.core.FlexGlobals;                                       if (match && match.length > 0)                                     {                                         label = new Label();                                         htmlText = '<a href="' + match[1] + '" target="_blank">' + match[1] + "</a>";                                     }                                     else if (fieldInfo.fieldName == "PROJNUM"){                                         label = new mx.controls.Label();                                         htmlText = "<a href='http://webistehere/PW/WebForm2.aspx?FirstName=" + FlexGlobals.topLevelApplication.firstName + "&LastName=" + FlexGlobals.topLevelApplication.lastName + "&email=" + FlexGlobals.topLevelApplication.email + "&ConstId=" + htmlText + "' target='_blank'><b>MP 116-1284</b></a>";                                     }                                     else                                     {                                         label = new PopUpText();                                     }


How do you know that it is MP 116-1284? Shouldn't that be coming from the data somewhere?

Add this to the index.mxml:

    <fx:Script>         <![CDATA[             public var firstName:String = "";             public var lastName:String = "";             public var email:String = "";         ]]>     </fx:Script>


Then in the splash widget you would import the FlexGlobals again and use line like these:

FlexGlobals.topLevelApplication.lastName = lastName.text


Don't forget to click the Mark as answer check and to click the top arrow (promote) as shown below:

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus
Andrea,

   Taking the values from the splash screen and trying to feed them to the URL is quite a bit to late in the process to do anything with the URL. You could take the values from the splash screen and set them to some public vars in the application and then get them from the Application using FlexGlobals.topLevelApplication.yourPublicVar. So something more like this:

import mx.core.FlexGlobals;                                       if (match && match.length > 0)                                     {                                         label = new Label();                                         htmlText = '<a href="' + match[1] + '" target="_blank">' + match[1] + "</a>";                                     }                                     else if (fieldInfo.fieldName == "PROJNUM"){                                         label = new mx.controls.Label();                                         htmlText = "<a href='http://webistehere/PW/WebForm2.aspx?FirstName=" + FlexGlobals.topLevelApplication.firstName + "&LastName=" + FlexGlobals.topLevelApplication.lastName + "&email=" + FlexGlobals.topLevelApplication.email + "&ConstId=" + htmlText + "' target='_blank'><b>MP 116-1284</b></a>";                                     }                                     else                                     {                                         label = new PopUpText();                                     }


How do you know that it is MP 116-1284? Shouldn't that be coming from the data somewhere?

Add this to the index.mxml:

    <fx:Script>         <![CDATA[             public var firstName:String = "";             public var lastName:String = "";             public var email:String = "";         ]]>     </fx:Script>


Then in the splash widget you would import the FlexGlobals again and use line like these:

FlexGlobals.topLevelApplication.lastName = lastName.text


Don't forget to click the Mark as answer check and to click the top arrow (promote) as shown below:
0 Kudos
AndreaGrygo
New Contributor
Robert,

Thank you, I figured there was a global variable, but didn't come across FlexGlobals.  I have a few questions:  Which mxml do I need to add the import and code to, SplashTitleWindow or SplashWidget?  Also, where in the code do I add FlexGlobals.topLevelApplication.lastName =lastName.text ?  I've tried a few places based on other threads (after the import statement, after the text boxes) and searches but I get errors, mostly undefined property of lastName.  If I'm declaring the variables in the index.mxml do I need to declare them in the Splash Widget also? 

Thank you for your help and generosity; so many of us would not be dabbling into Flex without your amazing widgets and support!

Andrea
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Andrea,

    OK, You have me a little concerned now. You are attempting to do something here that does require a little more than the ability to copy and paste. Well we'll give it a try, so here is what you need to do.

1. Add this code to the PopUpRendererSkin.mxml:
Add this Import to the top with the other imports:
import mx.core.FlexGlobals;


Then find the block of code in the PopUpRendererSkin.mxml that is similar to this and replace it with this:
                                    if (match && match.length > 0)
                                    {
                                        label = new Label();
                                        htmlText = '<a href="' + match[1] + '" target="_blank">' + match[1] + "</a>";
                                    }
                                    else if (fieldInfo.fieldName == "PROJNUM"){
                                        label = new mx.controls.Label();
                                        htmlText = "<a href='http://webistehere/PW/WebForm2.aspx?FirstName=" + FlexGlobals.topLevelApplication.firstName + "&LastName=" + FlexGlobals.topLevelApplication.lastName + "&email=" + FlexGlobals.topLevelApplication.email + "&ConstId=" + htmlText + "' target='_blank'><b>MP 116-1284</b></a>";
                                    }
                                    else
                                    {
                                        label = new PopUpText();
                                    }


2. In the SplashTitleWindow.mxml where I hope you added the text boxes you have the user filling out, you need to add these lines to the btnClose function.
FlexGlobals.topLevelApplication.lastName = lastName.text;[
FlexGlobals.topLevelApplication.firstName = firstName.text;
FlexGlobals.topLevelApplication.email = email.text;/CODE]

lastName was what I thought the id of your textBox that you added to the splash screen was if that is incorrect than you need to adjust the code to match what you have already done in your code.

3. And as I mentioned earlier you add these lines to the index.mxml:
    <fx:Script>
        <![CDATA[
            public var firstName:String = "";
            public var lastName:String = "";
            public var email:String = "";
        ]]>
    </fx:Script>
0 Kudos
AndreaGrygo
New Contributor
Robert,

I want to thank you for your assistance with this; without your help I don't know that this project would've been completed. 
Here is a link to the site if you are curious as to the end use.

Best,
Andrea
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Andrea,

   Ahhh... Now I see where you were going with this. I like the idea. Is there something wrong with the asp page right now? I got a bad url page display when I clicked on the subscribe in the popup.
0 Kudos