You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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];
}
})();
The text was updated successfully, but these errors were encountered:
matthewhenry1
changed the title
Filter returns to the UI UI, it should only return to the Answer hashOct 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.
The text was updated successfully, but these errors were encountered: