2013-04-26 30 views
1

我有一個表單,我想要構建一些簡單的驗證,但我似乎無法使其正常工作。該選項集有大約10個選項,但我只想爲其中一些選項創建一些驗證。例如,如果您是某種族,動態表單上將出現一個「指定」文本框,以允許您輸入數據,但如果您從選項集中進行某些選擇,該框將不會出現。我希望我已經清楚地解釋了這一點。Javascript語法和MS Dynamics中的行爲

目前,下面的代碼的工作原理如下:

另一個盒子是不是在形式負載可見,當您從optionset下拉列表中進行選擇,它出現在表格上,並允許您輸入數據。但是,只有在選擇某個選項時纔會出現。當做出錯誤的選擇時,它應該清除並再次變得不可見。目前,它保持可見狀態並在現場留言。默認情況下,該選項集在formload上沒有指定的值。

下面的代碼,我認爲它肯定是我的if語句不正確。

function Example_Other() { 
    Xrm.Page.getAttribute("new_choiceoptionset").getValue(); 
    if (Xrm.Page.getAttribute("new_choiceoptionset").getValue() == "White, Other 
(specify)" || "Asian, Other (specify)" || 
     "African, Other (specify)" || "Mixed, any other (specify)" || "Other ethnic group (specify)") { 
     Xrm.Page.ui.controls.get("new_othertextbox").setVisible(true); 
    } else { 
     Xrm.Page.ui.controls.get("new_othertextbox").setVisible(false); 
     Xrm.Page.getAttribute("new_othertextbox").setValue(null); 
    } 
} 

回答

0

我使用的選項的數值解決了這個問題,而不是字符串賦值...這並不理想(因爲價值可能需要隨着時間的推移而變化)但它提供了所需的功能。

例子:

var myValue = Xrm.Page.getAttribute("new_choiceexample").getValue(); 
if (myValue == 778300002 || 
myValue == 778300006 || 
myValue == 778300009 || 
myValue == 778300014 || 
myValue == 778300015) 
{ 
2

if陳述以不同的方式工作。你必須提供一個布爾表達式,所以如果你要這樣執行檢查,你必須做一些事情,如:

var myValue = Xrm.Page.getAttribute("new_choiceoptionset").getValue() 
if (myValue == "White, Other (specify)" 
    || myValue == "Asian, Other (specify)" 
    || myValue == "African, Other (specify)" 
    || myValue == "Mixed, any other (specify)" 
    || myValue == "Other ethnic group (specify)") 
{ 
    //Your code here 
} else { 
    //Other code here 
} 
+0

唉唉!像java一樣。我完全忘了這個語法。完美,這正是錯誤。謝謝。 :) – GrumP 2013-04-26 15:10:13

+0

嗯...看不到任何工作了。我想知道'和'有不同的影響嗎?原來的行爲現在甚至已經消失 – GrumP 2013-04-26 15:35:47

+0

屬性的內容是什麼? – Uby 2013-04-27 12:28:13