0

我创建了一个带有验证的 XFBML 表单。有几个字段对于最终用户是可选的。但是一旦启用验证,表单就会期望所有字段都被填写。那么,如何跳过可选字段的必需验证。

代码目前看起来像:

<fb:registration redirect-uri="http://www.sakshum.org/FbBloodDonorRegister" fields='[{"name":"name"},{"name":"first_name"},{"name":"last_name"}, {"name":"gender"}, {"name":"birthday"},{"name":"email"}, {"name":"cellPhone", "description":"Cell Number", "type":"text"}, {"name":"homePhone", "description":"Home Number", "type":"text"}, {"name":"officePhone", "description":"Office Number", "type":"text"}, {"name":"primaryAddress", "description":"Primary Address", "type":"text"}, {"name":"area", "description":"Locality/Village/Area", "type":"text"},{"name":"location"}]'  onvalidate="validated" width="530">
</fb:registration>
<script> 
function validated(form) {
    errors = {};    
    if(form.cellPhone.trim().length != 10){
        errors.cellPhone = "Cell number is required and should be 10 of digits";
    }

    if(form.homePhone.trim().length > 0){
        if(form.homePhone.trim().length != 10)
            errors.homePhone = "Home number should be 10 of digits";
    }   

    if(form.officePhone.trim().length > 0){
        if(form.officePhone.trim().length != 10)
            errors.officePhone = "Office number should be 10 of digits";
    }   

    if(form.homePhone.trim().length > 0 || form.officePhone.trim().length > 0){
        if(form.homePhone.trim() == form.officePhone.trim() || form.homePhone.trim() == form.cellPhone.trim() || form.officePhone.trim() == form.cellPhone.trim()){
            errors.homePhone = "Cell number, office number and home number cannot be same";
            errors.officePhone = "Cell number, office number and home number cannot be same";
        }
    }

  return errors;
}
</script> 
4

1 回答 1

0

看起来像 Facebook 的一个已知错误https://developers.facebook.com/bugs/139030226234017?browse=search_50551341bcf073b68986277

于 2012-09-15T23:48:48.923 回答