0

I have problems to validate in the client-side an array of inputs. Validations do not look right. I think I'm doing the right thing. I'm using the plugin bootstrap validator and laravel 5.2

client-side validation photo:

js code:

$('#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'
                    }

                }
            }




        }
    });

table view code:

<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>

Now It's validating but one tr only. When I add more tr it' not validating.

Error tr

4

1 回答 1

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/

希望能帮助到你

于 2017-06-03T04:36:06.760 回答