Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Prompter Functions
- This topic has 0 replies, 1 voice, and was last updated 4 years, 9 months ago by Sam Moffatt.
Viewing 0 reply threads
-
AuthorPosts
-
February 24, 2020 at 6:39 PM #39641
Sam MoffattParticipantCredit to @daniel_leu for this originally and I think a variant of them will be coming in the sample scripts. These are the two that I use personally and I figured I’d share them. I added this in my “Script Manager” form as “Prompter Functions”, so if you have that included already then you can add this as a new one.
If you’re going to use these, the calling function needs to be prefixed with
async
to make it work properly.// ========== Prompter Functions Start ========== // // NAME: Prompter Functions // VERSION: 1.0 /** * Prompter Functions for using the async system to handle some requests. */ // Temporary variable to store callback details. var prompterTempVar = undefined; /** * Prompt a confirmation dialog with a simple message. * * NOTE: This method uses async, please make sure your calling method is declared 'async'. * * @param {string} text - The text to display in the dialog for the confirmation. * @param {string} continueTitle - The text for the continue button. * @param {string} cancelTitle - The text for the cancel button. * * @return {boolean} Boolean result if the user confirmed or declined the dialog. */ function promptConfirm(text, continueTitle = 'Continue', cancelTitle = 'Cancel') { return new Promise(function(resolve, reject) { let prompter = Prompter .new(); prompter.cancelButtonTitle = cancelTitle; prompter.continueButtonTitle = continueTitle; prompter.show(text, ((status) => { if (status == true) { resolve(true); } else { resolve(false); } })); }); } /** * Prompt * * NOTE: This method uses async, please make sure your calling method is declared 'async'. * * @param {string} text - The text to display in the dialog for the confirmation. * @param {string} popupName - The prefix to display for the text box of the prompt. * @param {string} [continueTitle=Continue] - The text for the continue button. * @param {string} [cancelTitle=Cancel] - The text for the cancel button. * * @return {(string|boolean)} The input text or false if cancelled. */ function promptText(text, popupName, continueTitle = 'Continue', cancelTitle = 'Cancel'){ return new Promise(function(resolve, reject) { prompterTempVar = undefined; let prompter = Prompter .new(); prompter.addParameter(popupName, 'prompterTempVar') prompter.cancelButtonTitle = cancelTitle; prompter.continueButtonTitle = continueTitle; prompter.show(text, ((status) => { if (status == true && prompterTempVar) { resolve(prompterTempVar); } else { resolve(false); } })); }); } // ========== Prompter Functions End ========== //
You can also get a copy of this file here: https://github.com/pasamio/tftools/blob/master/scripts/js/prompter.js.
-
AuthorPosts
Viewing 0 reply threads
You must be logged in to reply to this topic.