我正在使用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> My form:
<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>这样做的想法是,显示给用户的submit按钮调用javascript函数checkForm(),然后禁用。
javascript函数查看我的每个文本框,如果至少选中一个文本框,则使用maskButton submit发送表单,该表单对用户隐藏。否则,显示警告消息。
我一直在使用getElementById()函数,但似乎无法从复选框中获得任何值(选中或未选中),因此我只是试图在警报中显示该值。如果未更改或未选中,此警报应显示选中或空的Y(与表单提交相同)。但不管我做了什么,警报都是空的。
另一种方法是在表单后面添加确认页,这样就不会丢失所有内容。我想让你看看我想做的事是否可能。谢谢
发布于 2014-01-10 16:43:02
没有任何Javascript指令,您可以使用xform:group技巧来呈现特定条件下的submit控件。就像这样:
<xforms:group ref=".[detail/other != '']">
<xforms:submit .../>
</xforms:group>-Alain
https://stackoverflow.com/questions/21048481
复制相似问题