2016-07-05 39 views
0

我正在appcelerator studio中構建自定義模式。如何在DatePicker上設置TextField上的數據

所以這是代碼:

<Alloy> 
    <Window id="modal_add_edit" onClose="cleanup" modal="true"> 
     <View class="container"> 
      <Label id="title" class="title"/> 
      <View class="separator"></View> 

      <TableView id="table" height="Titanium.UI.SIZE" layout="vertical">       
        <TableViewRow class="menu_item" top="25"> 
         <Label id="description" class="label" left="12" /> 
         <Picker id="comboDecription" left="20" selectionIndicator="true"> 
          <PickerColumn id="column1"> 
           <PickerRow title="Esposizione Tossica"/> 
           <PickerRow title="Stato civile"/> 
           <PickerRow title="Diet"/> 
          </PickerColumn> 
         </Picker> 
        </TableViewRow> 

        <!-- flags --> 
        <TableViewRow id="data" class="menu_item" top="25"> 
         <!--DATA START--> 
         <Label id="start_date" class="label" left="12" /> 
         <TextField id="textStartDate" class="field" 
          width="200px"></TextField> 
        </TableViewRow> 



      </TableView> 

      <View class="separator"></View> 
      <TableView id="tableButton" width="Titanium.UI.FILL" layout="horizontal">       
        <TableViewRow class="menu_item" top="25"> 
         <Button id="buttonClose" class="buttonClose" onClick="onClose" ></Button> 
         <Button id="buttonSave" class="buttonSave"></Button> 
        </TableViewRow> 
      </TableView> 
     </View> 
    </Window> 
</Alloy> 

所以我想,如果在textStartdate用戶點擊,則是的DatePicker顯示。這是我的控制器代碼:

var picker = Ti.UI.createPicker({}); 
$.textStartDate.addEventListener('click', function(e) { 
    picker.showDatePickerDialog({ 
     value : new Date(), // some date 
     callback : function(e) { 
      if (e.cancel) { 
       Ti.API.info('user canceled dialog'); 
      } else { 
       selectedDate = e.value; 
       $.textStartDate.setValue(String.formatDate(selectedDate, 'medium')); 
      } 
     } 
    }); 
}); 

然後,如果我嘗試點擊textStartDate,我能看到的DatePicker,然後我設定的數據,點擊OK按鈕,但我不能顯示在textStartDate數據。

如果我能在調試嘗試,代碼:

String.formatDate(selectedDate, 'medium') 

返回正確的數據,但我不能看到它在我的EditText

編輯 我添加了屏幕截圖

enter image description here

這是app.tss中的字段類

".field": { 
    left: "5%", 
    width: Titanium.UI.FILL, 
    borderRadius: 5, 
    hintTextColor: "#aaa", 
    color: "#333", 
    backgroundColor: "white" 
} 

回答

1

正如你說,String.formatDate(selectedDate, 'medium')將返回正確的數據,但你不能看到日期,所以我可以猜測,這可能是與你的文本字段的顏色屬性的問題。

請確保您已設置的顏色屬性不同的人比文本字段的backgroundColor,或者如果你沒有設置任何這樣的屬性,那麼我還是建議你設置顏色的backgroundColor屬性和一些默認值,以確保文本值在文本字段中正確可見。

有時取決於主題或操作系統類型,默認文本顏色& backgroundColor組合可能相同,這會使文本值不可見。

+0

表示字符串,返回正確的字符串,但如果我嘗試設置「pippo」是相同的。文本字段的背景顏色與文本的顏色不同 – bircastri

+0

您可以通過將默認值屬性設置爲任何內容並共享截圖來確認嗎?或只是分享一些代碼,以便我可以在這裏查看 –

+0

好的一刻,我分享屏幕截圖。但如果我嘗試繼續調試,在代碼中設置textStartdate的值之後,如果我嘗試檢查textStartdate的值是正確的,但它不顯示 – bircastri

相關問題