Dynamic options.addFields in beforeConstruct not working Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How the single threaded non blocking IO model works in Node.jsHow to build dynamic query by binding parameters in node.js-sql?Following tutorial - stuck on adding new templates under apostrophe-pages in app.jsunable to save image in widget apostropeCkeditor plugin configuration not workingScrapping dynamic data of a web page in nodejsIssue with displaying the image in an Apostrophe css widgetLoad widget dynamicallyOdoo REST API full response of relational modelHow to set baseUrl (also for apostrophe-multisite)

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Does the Black Tentacles spell do damage twice at the start of turn to an already restrained creature?

Tannaka duality for semisimple groups

Why not use the yoke to control yaw, as well as pitch and roll?

Constant factor of an array

Why are vacuum tubes still used in amateur radios?

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

Simple Line in LaTeX Help!

Google .dev domain strangely redirects to https

In musical terms, what properties are varied by the human voice to produce different words / syllables?

malloc in main() or malloc in another function: allocating memory for a struct and its members

Can two people see the same photon?

Why is it faster to reheat something than it is to cook it?

Resize vertical bars (absolute-value symbols)

"klopfte jemand" or "jemand klopfte"?

What adaptations would allow standard fantasy dwarves to survive in the desert?

What is a more techy Technical Writer job title that isn't cutesy or confusing?

Putting class ranking in CV, but against dept guidelines

Why is a lens darker than other ones when applying the same settings?

What does the writing on Poe's helmet say?

Why is std::move not [[nodiscard]] in C++20?

How to ask rejected full-time candidates to apply to teach individual courses?

Did any compiler fully use 80-bit floating point?

Monty Hall Problem-Probability Paradox



Dynamic options.addFields in beforeConstruct not working



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How the single threaded non blocking IO model works in Node.jsHow to build dynamic query by binding parameters in node.js-sql?Following tutorial - stuck on adding new templates under apostrophe-pages in app.jsunable to save image in widget apostropeCkeditor plugin configuration not workingScrapping dynamic data of a web page in nodejsIssue with displaying the image in an Apostrophe css widgetLoad widget dynamicallyOdoo REST API full response of relational modelHow to set baseUrl (also for apostrophe-multisite)



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I was looking at creating a simple generic reusable text-only widget in apostrophe-cms so I made the module text-only-widgets.



with the following code



In lib/modules/text-only-widgets/index.js



module.exports = 
extend: 'apostrophe-widgets',
label: 'Section Heading',

beforeConstruct: function (self, options) [])


;


In lib/modules/text-only-widgets/views/widget.html



 data.widget.sectionHeading 


Now I tried using the above widget in one of my pages as below:



 <div>

apos.area(data.page, 'aboutUsDescriptionTwo',
widgets:
'text-only':
addFields: [

name: 'sectionDescription', // set these fields dynamically
label: 'Section Description', // set these fields dynamically
type: 'string'

]



)

</div>


As shown in the below image, notice even after passing the addFields with label as Section Description to the text-only widget doesn't override the defaults set in the index.js.



enter image description here



enter image description here



I tried console.log on the options.addFields in index.js but it logs undefined as show below, I also tried few different variations but none works.



enter image description here










share|improve this question




























    0















    I was looking at creating a simple generic reusable text-only widget in apostrophe-cms so I made the module text-only-widgets.



    with the following code



    In lib/modules/text-only-widgets/index.js



    module.exports = 
    extend: 'apostrophe-widgets',
    label: 'Section Heading',

    beforeConstruct: function (self, options) [])


    ;


    In lib/modules/text-only-widgets/views/widget.html



     data.widget.sectionHeading 


    Now I tried using the above widget in one of my pages as below:



     <div>

    apos.area(data.page, 'aboutUsDescriptionTwo',
    widgets:
    'text-only':
    addFields: [

    name: 'sectionDescription', // set these fields dynamically
    label: 'Section Description', // set these fields dynamically
    type: 'string'

    ]



    )

    </div>


    As shown in the below image, notice even after passing the addFields with label as Section Description to the text-only widget doesn't override the defaults set in the index.js.



    enter image description here



    enter image description here



    I tried console.log on the options.addFields in index.js but it logs undefined as show below, I also tried few different variations but none works.



    enter image description here










    share|improve this question
























      0












      0








      0








      I was looking at creating a simple generic reusable text-only widget in apostrophe-cms so I made the module text-only-widgets.



      with the following code



      In lib/modules/text-only-widgets/index.js



      module.exports = 
      extend: 'apostrophe-widgets',
      label: 'Section Heading',

      beforeConstruct: function (self, options) [])


      ;


      In lib/modules/text-only-widgets/views/widget.html



       data.widget.sectionHeading 


      Now I tried using the above widget in one of my pages as below:



       <div>

      apos.area(data.page, 'aboutUsDescriptionTwo',
      widgets:
      'text-only':
      addFields: [

      name: 'sectionDescription', // set these fields dynamically
      label: 'Section Description', // set these fields dynamically
      type: 'string'

      ]



      )

      </div>


      As shown in the below image, notice even after passing the addFields with label as Section Description to the text-only widget doesn't override the defaults set in the index.js.



      enter image description here



      enter image description here



      I tried console.log on the options.addFields in index.js but it logs undefined as show below, I also tried few different variations but none works.



      enter image description here










      share|improve this question














      I was looking at creating a simple generic reusable text-only widget in apostrophe-cms so I made the module text-only-widgets.



      with the following code



      In lib/modules/text-only-widgets/index.js



      module.exports = 
      extend: 'apostrophe-widgets',
      label: 'Section Heading',

      beforeConstruct: function (self, options) [])


      ;


      In lib/modules/text-only-widgets/views/widget.html



       data.widget.sectionHeading 


      Now I tried using the above widget in one of my pages as below:



       <div>

      apos.area(data.page, 'aboutUsDescriptionTwo',
      widgets:
      'text-only':
      addFields: [

      name: 'sectionDescription', // set these fields dynamically
      label: 'Section Description', // set these fields dynamically
      type: 'string'

      ]



      )

      </div>


      As shown in the below image, notice even after passing the addFields with label as Section Description to the text-only widget doesn't override the defaults set in the index.js.



      enter image description here



      enter image description here



      I tried console.log on the options.addFields in index.js but it logs undefined as show below, I also tried few different variations but none works.



      enter image description here







      node.js apostrophe-cms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 11:44









      codincodin

      6411926




      6411926






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The addFields option is at the module level, it controls what fields exist for all instances of this widget. It is not an option that can be passed to individual instances of the widget via apos.area. Thus you can't do it in this way.



          The correct approach is to create a second module which uses extend to extend the first one and addFields, at the module level, to add the additional field. Then, in your area, you can offer just one of the two widget types, or both, as is appropriate to your needs.



          Thus in addition to lib/modules/text-only-widgets/index.js you would also have:



          // in lib/modules/text-plus-description-widgets/index.js
          module.exports =
          extend: 'text-only-widgets',
          label: 'Section Heading and Description',

          addFields: [

          name: 'sectionDescription',
          label: 'Section Description',
          type: 'string'

          ]
          ;


          And this widget would also have its own widget.html.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298892%2fdynamic-options-addfields-in-beforeconstruct-not-working%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The addFields option is at the module level, it controls what fields exist for all instances of this widget. It is not an option that can be passed to individual instances of the widget via apos.area. Thus you can't do it in this way.



            The correct approach is to create a second module which uses extend to extend the first one and addFields, at the module level, to add the additional field. Then, in your area, you can offer just one of the two widget types, or both, as is appropriate to your needs.



            Thus in addition to lib/modules/text-only-widgets/index.js you would also have:



            // in lib/modules/text-plus-description-widgets/index.js
            module.exports =
            extend: 'text-only-widgets',
            label: 'Section Heading and Description',

            addFields: [

            name: 'sectionDescription',
            label: 'Section Description',
            type: 'string'

            ]
            ;


            And this widget would also have its own widget.html.






            share|improve this answer



























              1














              The addFields option is at the module level, it controls what fields exist for all instances of this widget. It is not an option that can be passed to individual instances of the widget via apos.area. Thus you can't do it in this way.



              The correct approach is to create a second module which uses extend to extend the first one and addFields, at the module level, to add the additional field. Then, in your area, you can offer just one of the two widget types, or both, as is appropriate to your needs.



              Thus in addition to lib/modules/text-only-widgets/index.js you would also have:



              // in lib/modules/text-plus-description-widgets/index.js
              module.exports =
              extend: 'text-only-widgets',
              label: 'Section Heading and Description',

              addFields: [

              name: 'sectionDescription',
              label: 'Section Description',
              type: 'string'

              ]
              ;


              And this widget would also have its own widget.html.






              share|improve this answer

























                1












                1








                1







                The addFields option is at the module level, it controls what fields exist for all instances of this widget. It is not an option that can be passed to individual instances of the widget via apos.area. Thus you can't do it in this way.



                The correct approach is to create a second module which uses extend to extend the first one and addFields, at the module level, to add the additional field. Then, in your area, you can offer just one of the two widget types, or both, as is appropriate to your needs.



                Thus in addition to lib/modules/text-only-widgets/index.js you would also have:



                // in lib/modules/text-plus-description-widgets/index.js
                module.exports =
                extend: 'text-only-widgets',
                label: 'Section Heading and Description',

                addFields: [

                name: 'sectionDescription',
                label: 'Section Description',
                type: 'string'

                ]
                ;


                And this widget would also have its own widget.html.






                share|improve this answer













                The addFields option is at the module level, it controls what fields exist for all instances of this widget. It is not an option that can be passed to individual instances of the widget via apos.area. Thus you can't do it in this way.



                The correct approach is to create a second module which uses extend to extend the first one and addFields, at the module level, to add the additional field. Then, in your area, you can offer just one of the two widget types, or both, as is appropriate to your needs.



                Thus in addition to lib/modules/text-only-widgets/index.js you would also have:



                // in lib/modules/text-plus-description-widgets/index.js
                module.exports =
                extend: 'text-only-widgets',
                label: 'Section Heading and Description',

                addFields: [

                name: 'sectionDescription',
                label: 'Section Description',
                type: 'string'

                ]
                ;


                And this widget would also have its own widget.html.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 17:43









                Tom BoutellTom Boutell

                4,68612017




                4,68612017





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298892%2fdynamic-options-addfields-in-beforeconstruct-not-working%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript