0

I've been struggling to get this field validation to work. I'm using the JS validation for bootstrap from http://formvalidation.io/ and I've examined http://formvalidation.io/settings/ but nothing I've tried is working.

The field needs to validate a number input on a dynamically generated field using Razer C#, and the form is built to submit multiple models, therefore my name attribute is values[@i].Rating for each element that is generated, where i is an integer that is incremented in a loop.

The validation must make sure the client enters a number between 1 and 4 (inclusive), and if it is not a number between 1 and 4, it must show an error message such as "Please enter a number between 1 and 4". Here is my code, I first tried it with HTML attributes:

<input style="text-align: center" type="number" data-fv-between-min="1" data-fv-between-max="4" data-fv-between-inclusive="true" data-fv-between-message="Please enter a rating between 1 and 4" name="values[@i].Rating" class="form-control" />

but this didn't work, so I tried the javascript route with:

$(document).ready(function () {
    $('#newTSRForm').formValidation({
        framework: 'bootstrap',
        fields: {
            selector: '[type="number"]',
            input: {
                validators: {
                    between: {
                        min: 1,
                        max: 4,
                        message: 'Please enter a value between 1 and 4'
                    }
                }
            }
        }
    })
});

but my syntax is probably wrong or my thinking is incorrect. I also tried

$(document).ready(function () {
    $('#newTSRForm').formValidation({
        framework: 'bootstrap',
        fields: {
            'values[]': {
                validators: {
                    between: {
                        min: 1,
                        max: 4,
                        message: 'Please enter a value between 1 and 4'
                    }
                }
            }
        }
    })
});

But this doesn't work either. I have made sure my set up is correct so the problem is simply syntax or plausability. Can anybody advise?

1 Answer 1

1

¿ Did you look at http://formvalidation.io/examples/validating-field-special-name/ ? I think you have to add every single field with the AddField method of the Plugin.. Adding dynamic field

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.