[英]How to make a checkbox list appear after a selection from a drop-down menu, depending on drop-down menu selection?
[英]How do I make a text box appear after selecting an option from a drop-down menu in SuiteScript?
我是SuiteScript的新手。 現在我正在嘗試使用Suitelet制作表單。 在此表單中,我想向Suitelet添加邏輯,如果用戶從下拉菜單中選擇一個選項,則該選項將顯示一個文本框,供用戶在該選擇中輸入更多詳細信息。 到目前為止,這是我的代碼。
function suitelet(request, response) {
//create form
var form = nlapiCreateForm('Form Title');
var a = 'a';
var b = 'b';
var other = 'Other';
// adds dropdown menu
var selectField = form.addField('custpage_menu', 'select', 'Random Dropdown Menu');
selectField.addSelectOption('', '', false);
selectField.addSelectOption(a, a, false);
selectField.addSelectOption(b, b, false);
selectField.addSelectOption(other, other, false);
selectField.setMandatory(true);
//render a button for the user to submit form
form.addSubmitButton('Submit');
//load form
response.writePage(form);
}
我想在用戶選擇“其他”選項時顯示文本框。 所以在這種情況下,代碼行selectField.addSelectOption(other, other, false);
表示標記為“其他”的選擇選項。 此選擇在用戶單擊提交按鈕之前發生,因此我認為此時不會發生任何POST請求。
當用戶從下拉菜單中選擇一個選項時,我不確定會觸發什么樣的事件。 如果我可以通過我的代碼捕獲該事件,那么我希望我能夠根據選擇顯示一個文本框。
編輯:我忘了提一件事。 我根本不在處理記錄。 這只是一個由Suitelet生成的純表單。
您需要將客戶端腳本與Suitelet相關聯。 然后,當用戶從下拉列表中選擇一個選項時,使用字段更改功能捕獲事件。 在kitlet上創建文本框時必須隱藏文本框,然后在客戶端中使用field.isDisplay屬性,如下所示:
function fieldChanged(){
if (context.fieldId == 'custpage_menu') {
var boxField = context.currentRecord.getField('custpage_your_text_box_id');
if(other was selected){
boxField.isDisplay = true;
} else {
boxField.isDisplay = false;
}
}
}
我在這里添加了1.0中的代碼,雖然它在2.0開頭時,方法是一樣的,我將保留2.0版本,以防它對其他人有用:
function clientFieldChanged(type, name, linenum){
if(name == 'custpage_menu') {
var optionSelected = nlapiGetFieldValue('custpage_menu');
if(other was selected){
nlapiGetField('custpage_your_text_box_id').setDisplayType('normal');
} else{
nlapiGetField('custpage_your_text_box_id').setDisplayType('hidden');
}
}
}
使用客戶端腳本,您可以隱藏並以Suitelet形式顯示該字段。 因此,創建一個字段並僅使用客戶端腳本或suitelet隱藏該字段(setdisplaytype)。
在客戶端腳本中,您可以定義字段更改功能,如果選項是其他,則顯示文本字段。
我正在為函數添加一些參考代碼片段
用於在suitelet中設置客戶端腳本
form.clientScriptFileId = '264221';
對於客戶端的字段更改
/*Field Change event*/
function fieldChanged(scriptContext) {
var records = scriptContext.currentRecord;
if (scriptContext.fieldId == "datefiltertype") {
var type = records.getValue({
fieldId: 'datefiltertype'
});
if (type == "NOTWITHIN" || type == "WITHIN") {
jQuery("#fromdate_fs_lbl_uir_label").html("To");
jQuery("#todate_fs_lbl_uir_label").html("From");
jQuery("#fromdate_fs_lbl_uir_label").show();
jQuery("#fromdate").show()
} else {
jQuery("#fromdate").val("");
jQuery("#fromdate_fs_lbl_uir_label").hide();
jQuery("#fromdate").hide();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.