Prefilling of some fields

Hello,

Currently I am building an axure library with some basic reusable components. One of the components is a button so that some fields of a form can be prefilled with data (will be personal data after authentication).

So I have following components created:

A: button to prefill
B: name/firstname
C: address
D: email/telephone

You can make combinations with these components. Like ABC or ABD or ACD, etc. So I can’t make 1 component containing ABCD because you should be able to make different combinations.

What I would like to do is that when you click on the button the fields in component B, C and D are prefilled. I want to do this in the library so when I create a form I don’t have to do this every time again and again.

The problem here is that B, C and D are on seperate pages and I cannot access them when I add an onclick event on the button. I also tried to use javascript but axure(’@widget_name’).text or .val doesn’t work in Axure 8. I was thinking to use global variables but this doesn’t look the correct way.

Are there any other possibilities?

thanks,
wouter

I can’t quite picture this so I’ll need to ask some clarification questions:

  1. How is B,C, and D prefilled?
  2. Is B.C, and D some kind of form filled out by users?
  3. Is B,C, and D added onload?
  4. Are you wanting populate the components when a user clicks A or when it’s loaded on the page?

OK I’m just really confused a picture might help.

I uploaded an example library.

It contains 4 widgets (A,B,C,D). With this library you can make forms.
Example: I make a form with the widgets A, B and D.

I want that if you click on the button in widget A, the fields in widgets B, C and D are prefilled with some value. I want to program this behaviour in the library so I don’t have to do this in every form I create using this library.

But when I use an onclick event on the button I cannot select the widgets from B, C and D with the settext method.

Is this more clear?

thanks,
wouterTest.rplib (62.6 KB)

If I understand what you want, it can’t be done. Widgets on separate pages/masters can’t interact with one another. You’ll have to manually wire up the form each time you make it, or you’ll need to make pre-made masters that account for each possible variation.

Alternatively you could possibly use a repeater in a single master to make a configurable form.

Is there any way to use javascript to do the trick?

When clicking the button I can call a javascript and try to use the $axure text() or value() functions. But they don’t seem to work in Axure 8?

Note: this sort of thing isn’t officially supported by Axure :slight_smile:

There’s a bug in the JS file that I think has been around for a while that prohibits you from setting the text via JS. You essentially need to shim in the setWidgetText function because it’s missing. You’ll want to add this JS to your file, either using a plugin on axshare or using an event on PageLoad to add it. The code also fixes an issue with getting a global variable’s value. Anytime I am messing with JS I include this snippet:

(function () {
    $axure.internal(function($ax){
        //Fix for axure's bug where this function doesn't return anything.
        $ax.public.getGlobalVariable = $ax.getGlobalVariable = function(name) {
            return $ax.globalVariableProvider.getVariableValue(name);
        };

        //Currently setting the text on an input widget throws an error that SetWidgetFormText doesn't exist.
        // This shim fixes that error
        SetWidgetFormText = function(elementIds, value) {
            //Need to check if elementIds is a string or array. If it's a string this will never work.
            if(typeof elementIds == "string") {
                elementIds = Array(elementIds);
            }
            //This is the original function from Axure's expr.js
            for(var i = 0; i < elementIds.length; i++) {
                var elementId = elementIds[i];
                var inputId = $ax.repeater.applySuffixToElementId(elementId, '_input');
                var obj = $jobj(inputId);
                if(obj.val() == value || (value == '' && $ax.placeholderManager.isActive(elementId))) return;
                obj.val(value);
                $ax.placeholderManager.updatePlaceholder(elementId, !value);
                if($ax.event.HasTextChanged($ax.getObjectFromElementId(elementId))) $ax.event.TryFireTextChanged(elementId);
            }
        };
    });
})();

And then… you can do something like this:

$axure(’@TextFieldName’).text(‘New Text’)

I got this code from https://github.com/itorrey/EpiPen/blob/master/plugins/EpiPen/epi.js, which I found from a post here Set Axure variable via Javascript

Ok thanks.

For using javascript I use following hack: Ever wanted to add a RegEx to your prototype? Here's instant embedded AxQuery and JavaScript without header files/plugins

I modified it so it uses your function. But it doesn’t seem to work. Could you take a look?
See attached file. Note: for testing i put the button and field in the same widget.

When I add

//Currently setting the text on an input widget throws an error that SetWidgetFormText doesn't exist.
    // This shim fixes that error
    SetWidgetFormText = function(elementIds, value) {
        //Need to check if elementIds is a string or array. If it's a string this will never work.
        if(typeof elementIds == "string") {
            elementIds = Array(elementIds);
        }
        //This is the original function from Axure's expr.js
        for(var i = 0; i < elementIds.length; i++) {
            var elementId = elementIds[i];
            var inputId = $ax.repeater.applySuffixToElementId(elementId, '_input');
            var obj = $jobj(inputId);
            if(obj.val() == value || (value == '' && $ax.placeholderManager.isActive(elementId))) return;
            obj.val(value);
            $ax.placeholderManager.updatePlaceholder(elementId, !value);
            if($ax.event.HasTextChanged($ax.getObjectFromElementId(elementId))) $ax.event.TryFireTextChanged(elementId);
        }
    };

to the existing function, it fails.

Test.rplib (76.7 KB)

thanks,
wouter

I tried a few different things trying to get the code to work in your file and couldn’t get it work. Various errors come up in the console and I don’t have the time to debug this. But…

Here’s a working sample using the approach I use for injecting JS - see attached with a working sample with your function.

jsShim.rp (48.1 KB)

I usually put the inclusion on PageLoad, but I think for a library you may need to put in onload of one of the widgets.

Is someone capable of debugging? My javascript knowledge is not good enough.
I don’t understand why it works in your example and in my example it gives an error…

thanks,
wouter