我正在开发一个使用BetterFORMS的表单,该表单允许用户检查哪些字段适用于它们,然后发送数据进行处理。表单是完整且可以正常使用的-我只是想添加一些表单验证,如果未选中任何复选框,该表单验证将阻止用户发送请求。
模型和命名空间:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns="http://www.w3.org/2002/06/xhtml2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
<xsl:output method="xml" />
<xsl:template match="/">
<xforms:model id="documentsChecklist">
<xforms:instance>
<actionform xmlns="">
<xforms:model id="documentsChecklist">
<xforms:instance>
<actionform xmlns="">
<detail>
<other></other>
<otherText></otherText>
</detail>
</actionform>
</xforms:instance>
<xforms:bind id="other" nodeset="/actionform/detail/other" calculate="choose(. = 'Y', ., 'N')"/>
<xforms:bind nodeset="/actionform/detail/otherBox" relevant="/actionform/detail/other ='Y'" />
</xforms:model>
我的表格:
<div id="formBody"><br />
<xforms:select bind="other" appearance="full" align="right">
<xforms:item>
<xforms:label>Other</xforms:label>
<xforms:value>Y</xforms:value>
</xforms:item>
</xforms:select>
<xforms:input ref="/actionform/detail/otherText">
<xforms:label>Please specify:*</xforms:label>
</xforms:input>
<xforms:submit submission="formSubmit" id="send" class="ui-button" onclick="checkForm(this);return false;">
<xforms:label>Send</xforms:label>
</xforms:submit>
</div>
<xforms:submit submission="formSubmit" id="maskButton" class="ui-button">
<xsl:attribute name="style">display:none</xsl:attribute>
</xforms:submit>
<script type="text/javascript">
function checkForm(){
var otherCheckValue = document.getElementById('otherCheck-value');
alert(otherCheckValue.value);
if(boxesChecked != 0){
document.getElementById('maskButton-value').click();
}
}
</script>
</xsl:template>
</xsl:stylesheet>
想法是,显示给用户的“提交”按钮调用javascript函数checkForm(),然后被禁用。
javascript函数查看我的每个文本框,如果至少选中了一个文本框,则使用maskButton提交来发送表单,该表单对用户是隐藏的。否则,显示警报消息。
我一直在使用getElementById()函数,但是似乎无法从我的复选框(选中或未选中)中获取任何值,所以这就是为什么我只尝试在警报中显示该值。此警报应显示Y为已选中,如果未更改或未选中则为空(与表单提交相同)。但是,无论我尝试了什么,警报都是空的。
另一种方法是在表单后添加确认页面,这样就不会丢失所有内容。我要你看看我想做的事是否可行。谢谢
没有任何Javascript指令,您可以使用xforms:group技巧来呈现特定条件的Submit控件。像这样的东西:
<xforms:group ref=".[detail/other != '']">
<xforms:submit .../>
</xforms:group>
-阿兰
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句