2015-12-02 144 views
1

我已經創建了自定義驗證器的自動字段,它適用於第一對夫婦的一切,但是當我添加另外兩個字段時,驗證程序只是演示如何驗證第一個。汽車領域驗證程序liferay javascript

這是我的代碼:

<div id="groupwork-fields" > 
     <div class="lfr-form-row lfr-form-row-inline"> 
      <div class="row-fields"> 
       <aui:input fieldParam='name0' id="name0" cssClass="full-size" 
        name="name0" 
        label='<%=AwardConstants.LABEL_NAME %>' 
        value=""> 
        <aui:validator name="custom" errorMessage="fill-name"> 
         function (val, fieldNode, ruleValue) { 
          var result = true; 
           var selector = document.getElementById("<portlet:namespace/>select-group").value; 
           if (selector == 1 && val === "") { 
            result = false; 
           } 
           return result; 
         } 
        </aui:validator> 
       </aui:input> 
       <aui:input cssClass="full-size" 
        id="email0" fieldParam='email0' 
        name="email0" 
        label='<%=AwardConstants.LABEL_EMAIL %>' 
        value=""> 
        <aui:validator name="maxLength">100</aui:validator> 
        <aui:validator name="email"></aui:validator> 
        <aui:validator name="custom" errorMessage="fill-email"> 
         function (val, fieldNode, ruleValue) { 
          var result = true; 
          var name = document.getElementById("<portlet:namespace/>name0").value; 
          if (name !== "" && val === "") { 
            result = false; 
          } 
          return result; 
         } 
        </aui:validator> 
       </aui:input> 
      </div> 
     </div> 
    </div> 

這是我的腳本:

<aui:script> 
    AUI().use('liferay-auto-fields',function(A) { 
     new Liferay.AutoFields({ 
      contentBox: '#groupwork-fields', 
      fieldIndexes: '<portlet:namespace />groupworkIndexes' 
     }).render(); 
    }); 
    </aui:script> 

的事情是我總是第一個輸入的值,我想利用自己的對。

感謝

回答

1

爲我所看到的似乎是一個已知的bug:https://issues.liferay.com/browse/LPS-54188

+0

也許這是一個錯誤,但谷歌搜索我已經看到了關於他自己的規則定義腳本的一些例子:autoFields.on(「克隆」,功能(新野),雖然我不知道如何繼續 –

0

這裏,

我已經在汽車領域試圖用自定義的驗證年齡和它工作

<aui:input name="age" value='' label="Age"></aui:input> 


<aui:script use="liferay-auto-fields"> 
// declares rules 
var rules= {}; 

// override default error messages 
var fieldStrings = {}; 

AUI().use('aui-form-validator', 
    function(A) { 
    var DEFAULTS_FORM_VALIDATOR = A.config.FormValidator; 
    A.mix(
     DEFAULTS_FORM_VALIDATOR.RULES, 
     { 
     customRuleForAge:function (val, fieldNode, ruleValue) { 
      var result = false; 
      if (val >=18) { 
       result = true; 
      } 
      return result; 
      }, 
     }, 
     true 
    ); 
    A.mix(
     DEFAULTS_FORM_VALIDATOR.STRINGS, 
     { 
      customRuleForAge:"Age Should Be more than 18", 
     }, 
     true 
    ); 

    rules = { 
     <portlet:namespace/>age: { 
     customRuleForAge: true 
     } 
    }; 

    new A.FormValidator(
        { 
        boundingBox: '#<portlet:namespace/>researchSubjectForm', 
        fieldStrings: fieldStrings, 
        rules: rules, 
        showAllMessages: true 
        } 
       ); 
    } 
); 


    new Liferay.AutoFields({ 
    contentBox: '#research-subject-fields', 
    fieldIndexes: '<portlet:namespace />rowIndexes', 
    on: { 
     'clone': function(container){ 
      // container.guid will be the number for newly generated row. 

      rules["<portlet:namespace />age" + container.guid] = {customRuleForAge: true}; 

      fieldStrings["<portlet:namespace />age"+container.guid] = {customRuleForAge}; 

      } 
     } 

    }).render(); 

</aui:script>