2017-06-02 109 views
0

我有問題需要在客戶端驗證輸入數組。 驗證看起來不正確。我認爲我做對了。 我使用這個插件引導驗證和laravel 5.2驗證輸入數組引導驗證器 - Laravel 5.2

client-side validation photo:

JS代碼:

$('#forma').bootstrapValidator({ 
     message: 'Valor no valido', 
     feedbackIcons: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-remove', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 
     fields: { 
      'vtcanp[]': { 
       validators: { 
        notEmpty: { 
         message: 'Codigo de moneda requerido' 
        }, 
        stringLength: { 
         min: 3, 
         max: 4, 
         message: 'Código debe ser minimo de 3 y maximo 4 caracteres' 


        }, 
       } 
      }, 
      'vtprep[]': { 
       validators: { 
        notEmpty: { 
         message: 'Descripción de moneda requerido' 
        } 

       } 
      } 




     } 
    }); 

表視圖代碼:

<td width="17%"> 
             <input type="text" class="form-control" id="cantidad" name="vtcanp[]" /> 

            </td> 
            <td width="17%"> 
             <input type="text" class="form-control" id="precio" name="vtprep[]"/> 

            </td> 

現在它的驗證,但一個TR只。當我添加更多的tr時,它'不驗證。

Error tr

回答

0

試試這個: -

<form id="formid"> 
<div class="form-group" id="validatetr"> 
    <table> 
     <tr> 
      <td width="17%"> 
      <input type="text" class="form-control" id="cantidad" name="vtcanp[]" /> 
      </td> 
      <td width="17%"> 
      <input type="text" class="form-control" id="precio" name="vtprep[]"/> 

      </td> 
     <tr> 
    </table> 
</div> 
</form> //manage form according to your structure 

現在,你在響應動態添加TR添加此

var $template = $('#validatetr'), 
$clone = $template 
$('#formid') 
.formValidation('addField', $clone.find('[name="vtcanp[]"]')) 
.formValidation('addField', $clone.find('[name="vtprep[]"]')) 

而且從該更換零件的頂部: -

$('#forma') 
    .formValidation({ 
     framework: 'bootstrap', 
     icon: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-remove', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 

而這個鏈接可以幫助你: - http://formvalidation.io/examples/adding-dynamic-field/

希望它可以幫助

+0

沒有工作=(.. –

+0

有你包含的所有文件(formvalidation.js,bootstrap.min.js和bootstrap.min。 CSS)? – kunal

+0

是的,我包括所有,它不是形式validation.js它的bootstrapvalidator.js –