2010-11-19 8 views
0

dojoとdijitウィジェットを使用してかなり複雑なフォームを作成しようとしています。フォームには複数の「セクション」があり、ユーザーは既存のオブジェクトを(選択タグを使用して)添付するか、フォーム内にまったく新しいオブジェクトをインラインで作成できます。Dojo/Dijit:入力必須属性を動的に選択

私の入力は、条件に基づいたラジオボタンで表示され、javascriptで操作されます。私は問題やって、条件付きラジオボタンが選択されているに依存するそのもの(入力がレンダリングされているか否かに基づいて、必要なdijitのウィジェットを作っている。

私のhtml(実際にはJSP)

<div> 
    <input id="useExisting" type="radio" name="radio" checked value="useExisting" onclick="renderExistingInput()" /> <label for="useExisting">Use Existing</label> 
    <input id="new" type="radio" name="radio" value="new" onclick="renderNewInputs()"/> <label for="new">Create New</label> 
</div>  
<br> 
<div id="newInputs"> 
    <div class="row"> 
     <label class="label" for="newName">Name </label> 
     <span class="formInput"><input type="text" id="newName" name="newName" required="true" dojoType="dijit.form.ValidationTextBox"/></span> 
    </div> 
    <!-- More inputs with required="true"--> 

    <br> 
</div> 
<div id="existingInput> 
    <div class="row"> 
     <label class="label" for="existingSelect">Existing Object </label> 
     <span class="formInput"> 
      <select name="existingSelect" id="existingSelect" dojoType="dijit.form.Select"> 
       <!--JSTL tags for compiling list of options --> 
      </select> 
     </span> 
    </div> 
</div> 

を持っています添付のjavascript機能:

function renderExistingInput() { 

    dojo.fx.wipeOut(getWipeArguments('newInputs')).play(); 
    dojo.fx.wipeIn(getWipeArguments('existingInput')).play(); 
} 

function renderNewInputs() { 
    dojo.fx.wipeOut(getWipeArguments('existingInput')).play(); 
    dojo.fx.wipeIn(getWipeArguments('newInputs')).play(); 

} 

function getWipeArguments(id) { 
    var wipeArgs = { 
     node : id 
    }; 
    return wipeArgs; 
} 

ユーザーとの対話の基本的な「流れ」は、ユーザーであるラジオボタンをクリックし、正しいdivがその結果としてレンダリング私は、その後にレンダリングされていない入力が考慮されていない欲しいです。私はenではないこれをどうやってどうしたらいいか分かります。 dojoを介してその特定の属性を直接操作することは可能ですか?または、これを完全に行うためのより良い方法がありますか?

+0

http://stackoverflow.com/questions/2978570/disable-dojo-validation-on-certain-fields正しい方向に私を指摘したが、それのための:私の最後の関数は、「必要な」属性は以下のようになりますが変更しますまだ物事をするのにぎこちないやり方のようだ – BuffaloBuffalo

答えて

1

私の答えは私の顔を真っすぐ見つめていたようです。私は、私が出会ったさまざまな部分をまとめるだけでした。

function setWidgetRequiredAttributes(baseDomNodeId, requiredValue){ 
    foundWidgets = dijit.findWidgets(dojo.byId(baseDomNodeId)); 
    console.log(foundWidgets); 
    foundWidgets.forEach(function(widget){ 
     widget.required=requiredValue; 
    }); 
} 
関連する問題