我試圖驗證用戶輸入,如果他們沒有輸入必填字段,阻止他們傳遞輸入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個顯示框,你可以擺脫它。