Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.generateMXMLAttributes using NumberFormatter and CurrencyFormatter #1216

Open
javeiga opened this issue Dec 11, 2022 · 3 comments
Open

Comments

@javeiga
Copy link
Contributor

javeiga commented Dec 11, 2022

When we use NumberFormatter and CurrencyFormatter, we get the "this.generateMXMLAttributes is not a function" error at run time

@Harbs
Copy link
Contributor

Harbs commented Dec 11, 2022

How are you using it?

@javeiga
Copy link
Contributor Author

javeiga commented Dec 11, 2022

Using CurrencyFormatter as a custom Component

<mx:CurrencyFormatter
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.apache.org/royale/mx">
</mx:CurrencyFormatter>

Then im using it from the view like that:
<custom:CustomCurrencyFormatter id="currency" />

The error is displayed when initializing the view that uses it generating failure and not displaying the view.

@yishayw
Copy link
Contributor

yishayw commented Dec 12, 2022

The following works for me:

<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the CurrencyFormatter. -->
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
	xmlns:custom="*"
	xmlns:mx="library://ns.apache.org/royale/mx">

    <fx:Script>
        <![CDATA[
            import mx.events.ValidationResultEvent;

            private var vResult:ValidationResultEvent;

            // Event handler to validate and format input.
            private function Format():void {
                vResult = numVal.validate();

                if (vResult.type==ValidationResultEvent.VALID) {
                    var temp:Number = Number(priceUS.text); 
                    formattedUSPrice.text = usdFormatter.format(temp);
                } else {
                    formattedUSPrice.text = "";
                }
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        < id="usdFormatter" precision="2" 
                currencySymbol="$" decimalSeparatorFrom="."
                decimalSeparatorTo="." useNegativeSign="true" 
                useThousandsSeparator="true" alignSymbol="left"/>

        <mx:NumberValidator id="numVal" source="{priceUS}" property="text" 
                allowNegative="true" domain="real"/>
    </fx:Declarations>

    <mx:Panel title="CurrencyFormatter Example"
            width="800" height="600"
            horizontalCenter="0" verticalCenter="0">
        <mx:Form left="10" right="10" top="10" bottom="10">
            <mx:FormItem label="Enter U.S. dollar amount:">
                <mx:TextInput id="priceUS" text="" width="50%"/>
            </mx:FormItem>
            <mx:FormItem label="Formatted amount: ">
                <mx:TextInput id="formattedUSPrice" text="" width="50%" editable="false"/>
            </mx:FormItem>
            <mx:FormItem>
                <mx:Button label="Validate and Format" click="Format();"/>
            </mx:FormItem>
        </mx:Form>
    </mx:Panel>

</mx:Application>

Where custom:CustomFormatter is

<?xml version="1.0" encoding="utf-8"?>
<mx:CurrencyFormatter xmlns:mx="library://ns.apache.org/royale/mx">
</mx:CurrencyFormatter>

@joshtynjala joshtynjala changed the title his.generateMXMLAttributes using NumberFormatter and CurrencyFormatter this.generateMXMLAttributes using NumberFormatter and CurrencyFormatter Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants