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

How to initialize a widget #222

Closed
fredericgrati opened this issue Mar 8, 2013 · 2 comments
Closed

How to initialize a widget #222

fredericgrati opened this issue Mar 8, 2013 · 2 comments

Comments

@fredericgrati
Copy link

Hi everyone.

I want to find a way to initialize a widget by passing a data object.

Thanks to the video, we can see how we can pass a parameter from the html in order to retrieve it in the widget.
HTML

<div data-aura-widget=”navigation” data-aura-nbPage=”28”></div>

Widget

this.option.nbPage

Great, but if I have more than only one parameters… Do I have to declare all parameters into the html ?

And if I have a widget in the widget template, do I have to pass the parameter throw the 'parent' widget:
HTML

<div data-aura-widget=”toolbar” data-aura-nbPage=”28”></div>

Toolbar Template

<div data-aura-widget=”navigation” data-aura-nbPage=”{{nbPage}}”></div>

Navigation Widget

this.option.nbPage

I probably missed something...
Is it wrong to add an option parameter when we declare a widget with registerWidgetsSource.
In this way, we just have to declare the widget without passing parameters.
Maybe such a method already exists but I didn't find it.

I have another question: where can we post questions about aura? If I don’t propose something different or don’t add new features, I don't know where we can post questions about Aura.
Do you prefer that everyone opens an issue to regroup all questions?
Do you prefer that everyone use the file question of aura drive folder? Or do you prefer to open a google group ?
I found a google group "Aura" but it is empty. :/

@sbellity
Copy link
Member

sbellity commented Mar 8, 2013

Hi @freuh,

yep for the moment the easiest solution to pass options to a widget is through the data attributes.

Another way to use the options hash is to declare default values for your options in the widget itself (I just merged #212 into master).

You now can declare your widget like that :

define({
  options: {
    nbPage: 30
  },
  initialize: function() { this.html('...') }
})

You should be able to start widgets the same way we did it in previous aura : by calling this.sandbox.start(list) where list is a array of widgets to start (be to be true, i never used it).

If you have more complex needs, could you provide a more complete example ?

I don't really understand your question about registerWidgetSource... this method is used to declare a new endpoint (or source) to load widgets.

About the google group, (I think) I created it a few weeks ago. But never really used it.
We could use issues for the moment but I guess if the project gets more traffic we will eventually move the discussions somewhere else. In the meantime, I usually am available at #aura on Freenode.

@atesgoral
Copy link
Member

If you want to set some global settings for certain widgets, you could also use the per-module configuration feature of RequireJS. Suppose the path of your widget is myWidget.js. You can set some configuration for the widget like this:

requirejs.config({
    // The usual path, shim etc. configuration
    config: {
        myWidget: {
            foo: 1,
            bar: 2
        }
    }
});

Then, in your widget, include the special "module" module and access the configuration like this:

define([ "module" ], function (module) {
    var config = module.config();

    // config.foo === 1
    // config.bar === 2
});

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

4 participants