@@ -20,8 +20,9 @@ define([
2020'vp_base/js/com/com_generatorV2' ,
2121'vp_base/js/com/component/PopupComponent' ,
2222'vp_base/js/com/component/DataSelector' ,
23+ 'vp_base/js/com/component/SuggestInput' ,
2324'vp_base/js/m_apps/Subset'
24- ] , function ( stHTML , com_util , com_Const , com_String , com_generator , PopupComponent , DataSelector , Subset ) {
25+ ] , function ( stHTML , com_util , com_Const , com_String , com_generator , PopupComponent , DataSelector , SuggestInput , Subset ) {
2526
2627/**
2728 * StudentstTest
@@ -46,6 +47,8 @@ define([
4647groupingVariable :'' ,
4748group1 :'' ,
4849group2 :'' ,
50+ group1_istext :true ,
51+ group2_istext :true ,
4952pairedVariable1 :'' ,
5053pairedVariable2 :'' ,
5154testValue :'' ,
@@ -126,24 +129,58 @@ define([
126129// get result and load column list
127130vpKernel . getColumnCategory ( that . state . data , colCode ) . then ( function ( resultObj ) {
128131let { result} = resultObj ;
129- $ ( that . wrapSelector ( '#group1' ) ) . html ( '' ) ;
130- $ ( that . wrapSelector ( '#group2' ) ) . html ( '' ) ;
132+ $ ( that . wrapSelector ( '#group1' ) ) . val ( '' ) ;
133+ $ ( that . wrapSelector ( '#group2' ) ) . val ( '' ) ;
134+ that . state . group1 = '' ;
135+ that . state . group2 = '' ;
136+ that . state . group1_istext = true ;
137+ that . state . group2_istext = true ;
131138try {
132139var category = JSON . parse ( result ) ;
133- if ( category && category . length > 0 && colDtype == 'object' ) {
134- // if it's categorical column and its dtype is object, check 'Text' as default
135- category . forEach ( obj => {
136- let selected1 = obj . value === that . state . group1 ;
137- let selected2 = obj . value === that . state . group2 ;
138- $ ( that . wrapSelector ( '#group1' ) ) . append ( `<option value="${ obj . value } "${ selected1 ?'selected' :'' } >${ obj . label } </option>` ) ;
139- $ ( that . wrapSelector ( '#group2' ) ) . append ( `<option value="${ obj . value } "${ selected2 ?'selected' :'' } >${ obj . label } </option>` ) ;
140- } ) ;
140+ // if (category && category.length > 0 && colDtype == 'object') {
141+ // // if it's categorical column and its dtype is object, check 'Text' as default
142+ // category.forEach(obj => {
143+ // let selected1 = obj.value === that.state.group1;
144+ // let selected2 = obj.value === that.state.group2;
145+ // $(that.wrapSelector('#group1')).append(`<option value="${obj.value}" ${selected1?'selected':''}>${obj.label}</option>`);
146+ // $(that.wrapSelector('#group2')).append(`<option value="${obj.value}" ${selected2?'selected':''}>${obj.label}</option>`);
147+ // });
148+ // }
149+ var groupSuggest1 = new SuggestInput ( ) ;
150+ groupSuggest1 . setComponentID ( 'group1' ) ;
151+ groupSuggest1 . addClass ( 'vp-input vp-state' ) ;
152+ groupSuggest1 . setSuggestList ( function ( ) { return category ; } ) ;
153+ groupSuggest1 . setNormalFilter ( true ) ;
154+ groupSuggest1 . setPlaceholder ( 'Select value' ) ;
155+ $ ( that . wrapSelector ( '#group1' ) ) . replaceWith ( groupSuggest1 . toTagString ( ) ) ;
156+ var groupSuggest2 = new SuggestInput ( ) ;
157+ groupSuggest2 . setComponentID ( 'group2' ) ;
158+ groupSuggest2 . addClass ( 'vp-input vp-state' ) ;
159+ groupSuggest2 . setSuggestList ( function ( ) { return category ; } ) ;
160+ groupSuggest2 . setNormalFilter ( true ) ;
161+ groupSuggest2 . setPlaceholder ( 'Select value' ) ;
162+ $ ( that . wrapSelector ( '#group2' ) ) . replaceWith ( groupSuggest2 . toTagString ( ) ) ;
163+
164+ if ( category && category . length > 0 ) {
141165that . state . group1 = category [ 0 ] . value ;
142166that . state . group2 = category [ 0 ] . value ;
143167}
168+
169+ if ( colDtype == 'object' ) {
170+ // check as default
171+ $ ( that . wrapSelector ( '#group1_istext' ) ) . prop ( 'checked' , true ) ;
172+ $ ( that . wrapSelector ( '#group2_istext' ) ) . prop ( 'checked' , true ) ;
173+ that . state . group1_istext = true ;
174+ that . state . group2_istext = true ;
175+ } else {
176+ $ ( that . wrapSelector ( '#group1_istext' ) ) . prop ( 'checked' , false ) ;
177+ $ ( that . wrapSelector ( '#group2_istext' ) ) . prop ( 'checked' , false ) ;
178+ that . state . group1_istext = false ;
179+ that . state . group2_istext = false ;
180+ }
144181} catch {
145- $ ( that . wrapSelector ( '#group1' ) ) . html ( '' ) ;
146- $ ( that . wrapSelector ( '#group2' ) ) . html ( '' ) ;
182+ $ ( that . wrapSelector ( '#group1' ) ) . val ( '' ) ;
183+ $ ( that . wrapSelector ( '#group2' ) ) . val ( '' ) ;
147184}
148185} ) ;
149186} ) ;
@@ -231,7 +268,7 @@ define([
231268 testType, inputType, data,
232269 testVariable, testVariable1, testVariable2, groupingVariable,
233270 pairedVariable1, pairedVariable2,
234- group1, group2,
271+ group1, group2, group1_istext , group2_istext ,
235272 testValue, alterHypo, confInt
236273} = this . state ;
237274let codeList = [ ] ;
@@ -276,8 +313,8 @@ define([
276313code . appendLine ( "# Independent two-sample t-test" ) ;
277314// variable declaration
278315if ( inputType === 'long-data' ) {
279- code . appendFormatLine ( "vp_df1 = {0}[({1}[{2}] ==' {3}' )][{4}].dropna().copy()" , data , data , groupingVariable , group1 , testVariable ) ;
280- code . appendFormatLine ( "vp_df2 = {0}[({1}[{2}] ==' {3}' )][{4}].dropna().copy()" , data , data , groupingVariable , group2 , testVariable ) ;
316+ code . appendFormatLine ( "vp_df1 = {0}[({1}[{2}] == {3})][{4}].dropna().copy()" , data , data , groupingVariable , com_util . convertToStr ( group1 , group1_istext ) , testVariable ) ;
317+ code . appendFormatLine ( "vp_df2 = {0}[({1}[{2}] == {3})][{4}].dropna().copy()" , data , data , groupingVariable , com_util . convertToStr ( group2 , group2_istext ) , testVariable ) ;
281318} else if ( inputType === 'wide-data' ) {
282319code . appendFormatLine ( "vp_df1 = {0}[{1}].dropna().copy()" , data , testVariable1 ) ;
283320code . appendFormatLine ( "vp_df2 = {0}[{1}].dropna().copy()" , data , testVariable2 ) ;