【发布时间】:2011-05-12 20:46:10
【问题描述】:
我正在尝试使用 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。我想要的是那些未被渲染为不被认为是必需的输入。我不完全确定如何做到这一点。是否可以通过 dojo 直接操作该特定属性?还是有更好的方法来完全做到这一点?
【问题讨论】:
-
stackoverflow.com/questions/2978570/… 为我指明了正确的方向,但它似乎仍然是一种笨拙的做事方式
标签: javascript validation dojo