input

The 'input' function displays a dialog box for end-users to input one or more field values within a customizable form;
'input'函数提供对话框让用户输入一种或多种可定制类型的内容。

  • Prototype: input(sTitle, vFields, xOptions);
  • Synonym: form(sTitle, vFields, xOptions);
  • Parameters:

    1. sTitle: title of the dialog box;
      对话框名称
    2. vFields, an Array containing input fields to be shown in the dialog box; Each input field takes an item (JS Object) in the form of:
      包含用户可输入类型的一数组,每个可输入区包含一个下列形式的JS组件:
      {sField: 'field name', sLabel: 'description', vItems: [v1, v2, v3, ...], sInit: 'initial value', bRequired: true}
      Based on type of input fields, the actual attributes of the Object may vary, see below;
      具体类型如下:

      • sField: specifies the type of the input fields, can be one of the available tags: lineedit, combolist, comboedit, textarea, checkbox, color, date, time, datetime, file, files, savefile, and folder.
        指定输入框的类型,值可以为:lineedit, combolist, comboedit, textarea, checkbox, color, date, time, datetime, file, files, savefile和folder。

        lineedit: to construct a line-edit widget;
        单行输入区
        {sField: 'lineedit', sLabel: 'description', bReadonly: false, sInit: 'initial value', bRequired: true}

        combolist: to construct a simple list box with the dropdown button;
        下拉可选菜单(不可编辑)
        {sField: 'combolist', sLabel: 'description', vItems: ['item1', 'item2', 'item3'], nInit: 'initial index of selected item', bRequired: true}

        comboedit: to construct a combobox widget with dropdown and text editing;
        下拉可选菜单(可编辑)
        {sField: 'comboedit', sLabel: 'description', vItems: ['item1', 'item2', 'item3'], sInit: 'initial value', bRequired: true}

        textarea: to construct a textarea widget for multi-line text editing;
        多行输入区
        {sField: 'textarea', sLabel: 'description', bWordwrap: false, sInit: 'initial value', bRequired: true}

        checkbox: to construct one or more checkbox widgets; The initial check state can be specified by using a '|' character separating with the label text;
        一个或多个可以多选框
        {sField: 'checkbox', sLabel: 'description', vItems: ['1|AAA', '0|BBB', '1|CCC']}

        color: to construct a color-picker widget;
        颜色选框
        {sField: 'color', sLabel: 'description', sInit: 'initial color'}

        file: to construct a GetOpenFile widget for end-users to browse file system and select a file for reading;
        单文件选框
        {sField: 'file', sLabel: 'description', sTitle: 'title for GetOpenFile dialog box', sFilter: 'Text files (*.txt;*.ini);;All files (*.*)', sInit: 'initial directory', bRequired: true}

        files: to construct a GetOpenFiles widget for end-users to browse file system and select multiple files for reading;
        多文件选框
        {sField: 'files', sLabel: 'description', sTitle: 'title for GetOpenFile dialog box', sFilter: 'Text files (*.txt;*.ini);;All files (*.*)', sInit: 'initial directory', bRequired: true}

        savefile: to construct a GetSaveFile widget for end-users to browse file system and determine a file for writing;
        保存文件选框
        {sField: 'savefile', sLabel: 'description', sTitle: 'title for BrowseForFolder dialog box', sFilter: 'Text files (*.txt;*.ini);;All files (*.*)', sInit: 'initial directory', bRequired: true}

        folder: to construct a BrowseForFolder widget for end-users to browse file system and determine a folder/directory;
        文件夹选框
        {sField: 'folder', sLabel: 'description', sInit: 'initial directory', bRequired: true}

        date: to construct a line-edit widget for end-users to input a date;
        日期选框
        {sField: 'date', sLabel: 'description', sInit: new Date(), bRequired: true}

        time: to construct a line-edit widget for end-users to input a time;
        时间选框
        {sField: 'time', sLabel: 'description', sInit: new Date(), bRequired: true}

      • sLabel: a descriptive text for the input field;
        描述
      • vItems: an Array of pre-defined items related to the input fields;
        和输入区相关的预设内容
        • for 'combolist' and 'comboedit', it is an Array of pre-defined items to be listed in the dropdown list;
          对于'combolist'和'comboedit',则是预设的下拉选项。
        • for 'comboedit', each of items can also sepcify a return value in front of descriptive text separated with '|', e.g. ['A|Item1', 'B|Item2'];
          对于'comboedit',亦可指定返回值,并用'|'和选项分隔。
        • for 'checkbox', each of which takes the form of 'Initial-state|descriptive-text', e.g. ['true|Option1', '', 'false|Option2']; Each non-empty item constructs a checkbox widget, while the empty item works as a line-break;
          对于'checkbox'
      • sTitle: title text for the secondary dialog box; applicable for 'file', 'files', 'savefile' and 'folder';
        第二个弹窗的标题
      • sFilter: a string of file filter, with multiple file types separated with ';;'; applicable for 'file', 'files' and 'savefile';
      • sInit: a default value to initialize the input field;
      • bRequired: the value of the input field is required, it can't be left blank;
    3. xOptions: an optional Object;
      • nMinSize: minimal width of the input widget, in Pixels;
        最小宽度
      • nSpacing: spacing between each input fields, in Pixels;
        多个输入区之间的间隔
      • nMaxVisible: maximum visible items for listbox or combobox;
        最大可见选项数(listbox或combobox)
      • bVerticalLayout: true for a vertical layout, false for a form layout;
        对齐方式
  • Return Value: an Array containing values of each fields end-users input on the OK button pressed, or undefined on Cacnel.
  • Example:
var sDir=platform.getHomePath();
var sFilter='Text files (*.txt;*.ini);;All files (*.*)';
var vChks = ['AAAA', 'true|BBBBB', '', 'CCCCC', 'yes|DDDDD', '1|EEEEE', 't|FFFFF', '', 'y|GGGGG'];
var tDate = new Date(); tDate.setFullYear(2015); tDate.setMonth(6); tDate.setDate(27);
var vFields = [
    {sField: "lineedit", sLabel: 'lineedit', sInit: 'initial string'}
    , {sField: "combolist", sLabel: 'combolist', vItems: ['A', 'B', 'C'], sInit: 1}
    , {sField: "comboedit", sLabel: 'comboedit', vItems: ['X', 'Y', 'Z'], sInit: 'defval'}
    , {sField: "color", sLabel: 'color', sInit: '#ff0000'}
    , {sField: 'file', sLabel:'file', sTitle: 'open file', sInit: sDir, sFilter: sFilter}
    , {sField: 'files', sLabel:'files', sTitle: 'open files', sInit: sDir, sFilter: sFilter}
    , {sField: 'savefile', sLabel:'savefile', sTitle: 'save file', sInit: sDir, sFilter: sFilter}
    , {sField: 'folder', sLabel:'folder', sTitle: 'browse for folder', sInit: platform.getHomePath()}
    , {sField: 'checkbox', sLabel: 'check boxes', vItems:vChks}
    , {sField: 'date', sLabel:'date', sInit: tDate, bCalendar: true}
    , {sField: 'time', sLabel:'time', sInit: new Date()}
];
var vRes=input(plugin.getScriptTitle(), vFields, {nMinSize: 500, nSpacing: 6, bVerticalLayout: false});
if(vRes && vRes.length>0){
    var x=0;
    var sLineEdit=vRes[x++];
    var iComboList=vRes[x++];
    var sComboEdit=vRes[x++];
    var sColor=vRes[x++];
    var sFile=vRes[x++];
    var sFiles=vRes[x++];
    var sSaveFile=vRes[x++];
    var sFolder=vRes[x++];
    alert(sFolder);
}

以上示例脚本运行的结果如下图: