Ajax validation issue with array
I am trying to validate my codeigniter based from using jquery ajax. in my form i have dynamic fields which generates fields name like fault[0],fault[1],fault[2]...... this jquery script i am using works only the ID attribute & NAME attribute of a field are same. since array fields have [] marks i am unable to validate them.
i need to know a way doing this without id & same name rule.
i think this part manages the validate the fields only with same name & id.
-
- $.each(response.messages, function(key, value) {
- var element = $('#' + key);
-
this is my full script
- $('#form-user').submit(function(e) {
- e.preventDefault();
- var me = $(this);
- // perform ajax
- $.ajax({
- url: me.attr('action'),
- type: 'post',
- data: me.serialize(),
- dataType: 'json',
- success: function(response) {
- if (response.success == true) {
- // if success we would show message
- // and also remove the error class
- $('#the-message').append('<div class="alert alert-success">' +
- '<span class="glyphicon glyphicon-ok"></span>' +
- ' Data has been saved' +
- '</div>');
- $('.form-group').removeClass('has-error')
- .removeClass('has-success');
- $('.text-danger').remove();
- // reset the form
- me[0].reset();
- // close the message after seconds
- $('.alert-success').delay(500).show(10, function() {
- $(this).delay(3000).hide(10, function() {
- $(this).remove();
- });
- })
- }
- else {
- $.each(response.messages, function(key, value) {
- var element = $('#' + key);
-
- element.closest('div.form-group')
- .removeClass('has-error')
- .addClass(value.length > 0 ? 'has-error' : 'has-success')
- .find('.text-danger')
- .remove();
-
- element.after(value);
- });
- }
- }
- });
- });