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

Filter returns to the UI, it should only return to the Answer hash #972

Open
matthewhenry1 opened this issue Oct 9, 2020 · 0 comments
Open

Comments

@matthewhenry1
Copy link

matthewhenry1 commented Oct 9, 2020

I'm currently leveraging the transformer to force values into the Input Answer Hash shown in the view. The desire is to include "Hardcoded Text" in the view such as /Users/username/GitHub/. I have found that the transformer only impacts what is shown in the UI. So, to ensure that this "default text" (i.e. /Users/username/GitHub/) is preserved I have implemented a filter function to perform the same operation and store it to the answers hash. However what I'm finding is that filter is returning to the view and conflicting with transformer resulting in a duplicate. Such as:
/Users/username/GitHub/test/Users/username/GitHub/test

I have tried including a toggle to differentiate between submission and user input in the transformer since the filter is called before the transformer. But if I return nothing from the transformer in that final call.

Can be reproduced below.

const os = require("os"); // os
const inquirer = require("inquirer"); // cli prompt

class Package {
    constructor(name) {
        this.name = {
            value: name,
            question: { en: "What is the name of your app?" },
            type: "input",
            submitted: false,
            transformer: function (input) {
                // this runs each time a user enters an input
                return `${os.homedir()}/GitHub/${input}`;
            },
            filter: function (input) {
                // this runs first on submission
                return `${os.homedir()}/GitHub/${input}`;
            },
            validate: function (input) {
                // this runs after filter submit
                return true;
            },
        };
    }
    // return an array of property names
    getAllPropertyNames() {
        return Object.getOwnPropertyNames(this);
    }
}
(async function () {
    const package = new Package();
    const allPropertyNames = package.getAllPropertyNames();

    for (const prop of allPropertyNames) {
        const answer = await inquirer.prompt([
            { name: prop, message: `${package[prop].question.en}`, type: package[prop].type, validate: package[prop].validate, transformer: package[prop].transformer, filter: package[prop].filter, choices: package[prop].choices },
        ]);
        package[prop].value = answer[prop];
    }
})();

@matthewhenry1 matthewhenry1 changed the title Filter returns to the UI UI, it should only return to the Answer hash Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant