{"id":5428,"date":"2012-11-01T10:13:00","date_gmt":"2012-11-01T18:13:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=5428"},"modified":"2012-11-01T10:14:09","modified_gmt":"2012-11-01T18:14:09","slug":"powershell-studio-new-form-template","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2012\/11\/01\/powershell-studio-new-form-template\/","title":{"rendered":"PowerShell Studio: New Form Template"},"content":{"rendered":"<p>In the (v3.1.9) service release we introduced a new form template called: Wizard Template.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Wizard-Template.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Wizard Template\" border=\"0\" alt=\"Wizard Template\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Wizard-Template_thumb.png\" width=\"244\" height=\"124\"><\/a><\/p>\n<p>This template simulates an application wizard by utilizing a TabControl to represent the various pages of the wizard. The template also includes navigation buttons that enable and disable depending on the current position and if the controls validate.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Wizard-Tabs-Navigation.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Wizard Tabs &amp; Navigation\" border=\"0\" alt=\"Wizard Tabs &amp; Navigation\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Wizard-Tabs-Navigation_thumb.png\" width=\"244\" height=\"163\"><\/a><\/p>\n<p>Each tab page has a sample input that must either be entered or checked in order to proceed. <\/p>\n<p>For example, tab page \u201cStep 1\u201d has a textbox that must have information entered before proceeding:<\/p>\n<p>Before Entering Text:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Enter-Name-Empty.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Enter Name Empty\" border=\"0\" alt=\"Enter Name Empty\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Enter-Name-Empty_thumb.png\" width=\"244\" height=\"163\"><\/a><\/p>\n<p>The Next button is disabled.<\/p>\n<p>&nbsp;<\/p>\n<p>After Entering Text:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Enter-Name-After.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Enter Name After\" border=\"0\" alt=\"Enter Name After\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Enter-Name-After_thumb.png\" width=\"244\" height=\"163\"><\/a><\/p>\n<p>The Next button is enabled because the text box has passed validation.<\/p>\n<p>&nbsp;<\/p>\n<p>The same applies to the other tab pages until the final page, which enables the Finish button once all the other pages are validated:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Final-Page.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Final Page\" border=\"0\" alt=\"Final Page\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2012\/10\/Final-Page_thumb.png\" width=\"244\" height=\"163\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Wizard Template Functions:<\/strong><\/p>\n<p>The template includes functions to handle navigation and provide a place to insert your custom validation script. This validation script is called whenever the user tries to navigate to the next page in the wizard.<\/p>\n<p><font color=\"#008080\">Validate-WizardPage<\/font><\/p>\n<p>This function is called whenever the Wizard needs to validate a TabPage. Place your custom validation code here. Return <i>True<\/i> if the page is valid otherwise <i>False<\/i> if validation fails. The Wizard calls this function when the user is navigating to another tab page. If the function returns a value of <i>False<\/i> it will prevent the user from proceeding. The result of this function also influences whether the Next and Finish buttons are enabled or disabled.<\/p>\n<pre><span style=\"color: #0000ff\">function<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #008080\">Validate-WizardPage<\/span><span style=\"color: #000000\">\n{\n<\/span><span style=\"color: #008000\">&lt;#\n    Add TabPages and place the validation code in this function\n#&gt;<\/span><span style=\"color: #000000\">\n    [OutputType([boolean])]\n    <\/span><span style=\"color: #0000ff\">param<\/span><span style=\"color: #000000\">([System.Windows.Forms.TabPage]<\/span><span style=\"color: #8b0000\">$tabPage<\/span><span style=\"color: #000000\">)\n    \n    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$tabPage<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$tabpageStep1<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #008000\">#TODO: Enter Validation Code here for Step 1<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #0000ff\">-not<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$textboxName<\/span><span style=\"color: #000000\">.Text)\n        {\n            <\/span><span style=\"color: #0000ff\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$false<\/span><span style=\"color: #000000\">    \n        }\n        \n        <\/span><span style=\"color: #0000ff\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$true<\/span><span style=\"color: #000000\">\n    }\n    <\/span><span style=\"color: #0000ff\">elseif<\/span><span style=\"color: #000000\"> (<\/span><span style=\"color: #8b0000\">$tabPage<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$tabpageStep2<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #008000\">#TODO: Enter Validation Code here for Step 2<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$checkboxCheckToContinue<\/span><span style=\"color: #000000\">.Checked)\n        {\n            <\/span><span style=\"color: #0000ff\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$true<\/span><span style=\"color: #000000\">\n        }\n        \n        <\/span><span style=\"color: #0000ff\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$false<\/span><span style=\"color: #000000\">\n    }<\/span><\/pre>\n<p>\u2026<\/p>\n<p>&nbsp;<\/p>\n<p><font color=\"#008080\">Update-NavButtons<\/font><\/p>\n<p>Call this function when you wish to validate the current page and update the states of the navigation buttons.<\/p>\n<p>This function should be called when the state of a control changes and has influence on whether the user can continue or not. For example, in the \u201cStep 1\u201c&nbsp; tab page, the Text Box must have text before proceeding; as a result, <font color=\"#008181\">Update-NavButton<\/font> is called whenever the TextBox\u2019s text changes.<\/p>\n<pre><span style=\"color: #8b0000\">$textboxName_TextChanged<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">{\n    <\/span><span style=\"color: #008080\">Update-NavButtons<\/span><span style=\"color: #000000\">\n}<\/span><\/pre>\n<p>In addition to validation, the Next, Back and Finish buttons are enabled or disabled depending on the current tab\u2019s position.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Finish Button<\/strong><\/p>\n<p>Once all the tabs have been validated, the user can press the Finish Button. Place your custom script in the Finish button\u2019s Click event to handle any finalization.<\/p>\n<pre><span style=\"color: #8b0000\">$buttonFinish_Click<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">{\n    <\/span><span style=\"color: #008000\">#-------------------------------------------------------<\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #008000\"># TODO: Place finalization script here<\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #008000\">#-------------------------------------------------------<\/span><span style=\"color: #000000\">\n    \n}\n<\/span><\/pre>\n<p>Note: The Finish button has its DialogResult property set to OK; therefore, it will close the form once the user clicks on the button.<\/p>\n<p>&nbsp;<\/p>\n<p>For more details on the TabControl, please refer to the <a href=\"http:\/\/www.sapien.com\/blog\/2011\/10\/28\/primalforms-2011-spotlight-on-the-tabcontrol\/\" target=\"_blank\">Spotlight on the TabControl<\/a> blog article. <br \/>For more details on the Button control, please refer to the <a href=\"http:\/\/www.sapien.com\/blog\/2011\/06\/07\/primalforms-2011-spotlight-on-the-button-control\/\" target=\"_blank\">Spotlight on the Button Control<\/a> blog article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the (v3.1.9) service release we introduced a new form template called: Wizard Template. This template simulates an application wizard by utilizing a TabControl to represent the various pages of the wizard. The template also includes navigation buttons that enable and disable depending on the current position and if the controls validate. &nbsp; Each tab [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[456,25],"tags":[665,28,1016,81,425],"class_list":["post-5428","post","type-post","status-publish","format-standard","hentry","category-primalscript-studio","category-windows-powershell","tag-form","tag-powershell","tag-powershell-studio","tag-templates","tag-wizard"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=5428"}],"version-history":[{"count":5,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5428\/revisions"}],"predecessor-version":[{"id":5497,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5428\/revisions\/5497"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=5428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=5428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=5428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}