Establishing a standard flatiron-director route (within the element) using the polymer core-pages component

This particular query is closely linked with issues surrounding the usage of flatiron-director/core-pages SPA in conjunction with route-specific JavaScript functions and default routes. While the solution proposed may be effective, my limited expertise in polymer (and JavaScript) makes it challenging for me to identify the appropriate event listener in my specific scenario:

So, the question arises: how and where should one specify a suitable event listener to establish the default route when utilizing flatiron-director within a polymer element, especially if the template of the said element does not incorporate "is='auto-binding'"? To clarify, even though the index.html page that imports the following element specifies a template using "is='auto-binding'", the automatic addition of the default "#itemsList" route to the URL upon hitting index.html alone is not occurring:

Below is the code snippet of the element to elucidate what I am striving to convey/achieve. The flatiron routing functions as intended (if #itemsList or #itemOpen is manually entered into the URL and the browser's previous or next buttons are utilized), however, the default #itemsList is not automatically appended to the URL upon accessing index.html independently:

<polymer-element name="my-app" attributes="user items connected">

<template>

    <flatiron-director id="page-director" route="{{route}}" autoHash on-director-route="{{ routeChanged }}"></flatiron-director>

    <!-- HIGH LEVEL APP LAYOUT ELEMENT -->
    <core-header-panel id="appHeader" mode="standard">

        <!-- OUTER APP TOOLBAR ELEMENT -->
        <core-toolbar id="appToolbar">
            <paper-icon-button id="navicon" icon="arrow-back" on-tap="{{ showItems }}"></paper-icon-button>
            <span flex>App Name</span>
            <paper-icon-button id="searchbutton" icon="search"></paper-icon-button>
        </core-toolbar>

        <!-- MAIN CONTENT ELEMENTS -->

        <!-- ATTEMPT FLATIRON ROUTING -->
        <core-pages id="mainPages" selected="{{route}}" valueattr="name">

            <my-items-element name="itemsList" on-core-activate="{{ itemSelect }}" user="{{user}}" items="{{items}}" item="{{item}}"></my-items-element>

            <item-open-scaffold-element name="itemOpen" user="{{user}}" item="{{item}}" hidden></item-open-scaffold-element>

        </core-pages>


    </core-header-panel>

</template>

<script>
    Polymer('my-app', {

        route: "itemsList",

        itemSelect: function(e, detail, sender) {
            if (sender.shadowRoot.activeElement == null || sender.shadowRoot.activeElement.nodeName != "PAPER-MENU-BUTTON"){
                // Ensure the user hasn't clicked on the item menu dropdown to perform alternative actions (or another element with actions for that matter)
                // (i.e. make sure the user intends to open the item)
                this.openItem();
            }
        },

        openItem: function() {
            this.$.mainPages.children.itemOpen.hidden = false;
            this.$.mainPages.selected = "itemOpen";
            //this.route = "scaffoldPage";
        },

        showItems: function() {
            this.$.mainPages.children.itemOpen.hidden = true;
            this.$.mainPages.selected = "itemsList";
        }
    });
</script>

<script>
    var template = document.querySelector('template');

    template.addEventListener('template-bound', function() {
        this.route = this.route || "itemsList";
    });
</script>

Answer №1

Jeff pointed out that the ready() lifecycle method serves as an internal equivalent to the template-bound event outside of the element. Therefore, in the example provided above, all you need to do is add the following line inside the ready() function of your Polymer element:

this.route = this.route || "itemsList"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update JSON data in ng-blur event using AngularJS

Could you offer some guidance on how to push the content from a text box into JSON when I click outside of the box? Below is the code for my text box: <input type="text" name="treatmentCost" class="form-control" ng-model="addTemplate" /> And here i ...

CSS classes designed to mimic JavaScript object attribute-value pairs

I stumbled upon some interesting css class-value combinations within HTML tags. It seems like a specific JavaScript code is interpreting this, but it's something I haven't encountered before. I came across this on www.woothemes.com/flexslider/ (y ...

What could be the reason for my array parameter not being included in the POST request

When working on my laravel 5.7 / jquery 3 app, I encountered an issue while trying to save an array of data. After submitting the form, I noticed that only the _token parameter is being sent in the POST request as seen in the browser console: let todos_co ...

A JavaScript function utilizing lodash's forEach method that is returning an undefined value

I've encountered a problem while developing a ReactJS app. In one of my functions called filterSelected, I have a for loop that iterates through an array of region names (e.g. ["Thailand", "Malaysia"]) and is supposed to return an array of their corre ...

Vue.js is not properly synchronizing props in a child component when the parent component is updating the property

When it comes to communication between components, my structure looks something like this: <div id=chat-box> <div class="wrapper"> <div> <chat-header></chat-header> <message-container :chat="chat"></message ...

Load components in NextJS lazily without utilizing `next/dynamic`

Currently, I am in the process of developing a component (Editor) that should always be lazy-loaded in React applications. However, I need it to be compatible with any React app. While I have successfully implemented lazy loading with Create React App usi ...

How is it possible that this React setter is effectively working despite the fact that it is within a stale closure

I've come across this interesting function that I need help understanding. The randomize function seems to be consistent in its behavior despite multiple renders, thanks to being wrapped in a useCallback. Each time the randomize button is clicked, it ...

How to successfully close a jQuery dialog within a user control

My user control has a list view with a hyperlink (LnkDelete) that triggers a jQuery dialog. Here is the javascript code responsible for this functionality: $('#LnkDelete').live('click', function (e) { var page = $(this).at ...

Why is the value of the select element in AngularJS an object?

Here is a JSON object: { "9000A": { "LOCname":"A Place", "LOCid":"9000A" }, "2700C": { "LOCname":"C Place", "LOCid":"2700C" }, "7600B": { "LOCname":"B Place", "LOCid":"7600B" } } To ...

How can I make this NextJS component show its width as soon as the page loads?

When I try to run this code to retrieve the browser's screen width, I encounter the following error: ReferenceError: window is not defined The commented-out code works fine with a default value of 0 and updates correctly when the browser width chan ...

automatically loading data using jquery

I am currently utilizing a windows service along with an html+j query page to interact with a web service. Whenever a Document is scanned on our device, I aim to display: name, country, and Passport number on our webpage. Although I have successfully a ...

Unpredictable Behavior of CSS Transition with JS createElement() Function

I'm using JavaScript to create a div element and I'm adding the CSS property transition: .5s linear top; When the user clicks on the element (onmousedown event), it is supposed to smoothly move to the top of the screen and then be deleted using ...

Is it optimal to have nested promises for an asynchronous file read operation within a for loop in Node.js?

The following Node.js function requires: an object named shop containing a regular expression an array of filenames This function reads each csv file listed in the array, tests a cell in the first row with the provided regular expression, and returns a n ...

After refreshing the page, the local storage does not appear

I've been struggling to get it working for hours with no luck. After submitting the form, I create local storage values for name, surname, and email so that they can be automatically filled in the form next time without requiring the user to retype th ...

Tips for creating AngularJS forms which display radio buttons and populate data from a JSON file

I'm having trouble displaying the json data correctly. How can I show the radio buttons from my json file (plunker demo)? Additionally, I want to validate the form when it is submitted. Here is the HTML code: <my-form ng-app="CreateApp" ng- ...

In VueJS, where specifically do you typically look to catch emitted events?

Let's set the stage: export default Vue.extend({ name: 'Home', computed: { ...mapState('user', ['card']), }, created() { this.fetchData(); }, mounted() { this.$once('dataLoaded', () => { if ...

The phenomenon of jQuery AJAX converting the escape character from %20 to + has been observed

I am encountering an issue with my jQuery AJAX function which is supposed to save an image path to the database. Below is an example parameter: var data = {}; data['url'] = "Path%20to%20URL"; Normally, if there is a space or %20, it sh ...

Difficulty with Angular JS` ng-repeat functionality

I attempted to create a sample similar to the ones found on https://angularjs.org/ Here is the JS fiddle I put together. Could someone provide assistance? What seems to be the issue? The HTML code is as follows: <h2> To Do </h2> <div ng- ...

javascript if an error occurs, refresh the webpage

Currently, I am inquiring about the most effective method for managing JavaScript errors. Given that my application relies heavily on JavaScript, despite diligent testing efforts, encountering bugs is almost certain. I'm interested in knowing if ther ...

When you click on the column header to sort, the corresponding column row changes color in JavaScript

https://i.sstatic.net/4ELuv.jpg When a user clicks on a column to sort, the color of the column changes or highlights the row. In my tablesorter with ascending and descending sorting capabilities, I want the sorted column to change colors for better visib ...