我试图验证用户输入,如果他们没有输入必填字段,阻止他们传递输入UI。到目前为止,似乎按钮框实际上并没有按顺序运行脚本,或者它似乎不存储变量,直到整个脚本完成。我怎么能绕过这个?
clearLog();
clearGlobals();
clearSymbols();
dt = currentDataTable();
inputGUI = newWindow( "Input Selection UI", << modal,
//Step Name input box
hListBox(
textBox("1. Enter some text input"),
stepTextEdit = textEditBox(),
),
//Column Section input box
hListBox(
vListBox(
choosesrc=filterColSelector( nLines( 6 ) ),
chooseSRC << numeric( 0 ),
),
vListBox(
lineUpBox( nCol( 1 ), spacing( 2 ),
buttonBox( "Add Column >>",
listcols2 << Append( chooseSRC << getSelected );
),
buttonBox( "<< Remove Column",
listcols2 << removeSelected;
),
),
),
vListBox(
listcols2 = colListBox( nLines( 3 ), minItems(1), maxItems(1) ), //col list box with no columns inside
);
),
//Footer Section and OK/Cancel Buttons
hListBox(
buttonBox("OK",
//Collect all variables from input boxes
uinp_stepName = stepTextEdit << getText;
uinp_colssrc=listcols2 << getItems;
// Input Validation Logic
if ( IsMissing(uinp_stepName) == 1,
(nw_error_uinp_stepName = New Window("Error ", << Modal,
VList Box(
Text Box("Text input is missing"),
HList Box(
Button Box ( "OK" ),
),
);
);
break(); // Only send 1 error at a time
)
);
if ( nItems(uinp_colsSRC) == 0,
(nw_error_uinp_colssrc=New Window("Error ", << Modal,
VList Box(
Spacer Box( Size (5, 5) ),
Text Box("Column input is missing"),
Spacer Box( Size (15, 15) ),
HList Box(
Button Box ( "OK" ),
),
);
);
break(); // Only send 1 error at a time
)
);
),
buttonBox("Cancel", Print("User cancelled operation!"); Stop() ),
),
);另外,为此目的,请参阅内联消息<< On Validate(expression)to New Window()。
我不认为它正在评估任何不按顺序的事情。问题是您正在尝试修改以逗号分隔的行中的filterColSelector对象。 逗号用于分隔嵌套在该垂直列表框中的不同显示对象。 用这个代码片段交换你应该是好的:
vListBox(
choosesrc=filterColSelector( nLines( 6 ), << numeric( 0 ))
)
*此外,我不确定你是否打算在该vListBox中追加任何其他东西,但由于它只包含1个显示框,你可以摆脱它。