Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('form[name="product"]').on('submit', function () {
- var _self = $(this);
- _self.each(function () {
- var $textarea = $(this);
- $textarea.val(CKEDITOR.instances[$textarea.attr('id')].getData());
- });
- var data = new FormData(_self[0]);
- data.append('ajax', true);
- $.ajax({
- method: "POST",
- url: Routing.generate(route, route_params),
- data: data,
- cache: false,
- contentType: false,
- processData: false,
- enctype: 'multipart/form-data',
- beforeSend: function () {
- $('[data-toggle="tab"]').find('i').remove();
- $('input,textarea,select').parent().removeClass('has-error').find('span.help-block').remove();
- _self.find('[type="submit"]').find('i').remove();
- $('<i class="fa fa-spin fa-spinner"></i>').prependTo(_self.find('[type="submit"]'));
- }
- })
- .done(function (msg) {
- if (msg.valid == true) {
- } else if (msg.valid == false) {
- var errors = JSON.parse(msg.errors);
- for (var k in errors) {
- var selector;
- var path = errors[k].cause.propertyPath.split('.');
- if (path.length == 2) {
- selector = _self.attr('name') + '_' + path[1];
- } else {
- var path1 = path[0].replace('children[', '');
- path1 = path1.replace(']', '');
- var path2 = path[1].replace('data[', '');
- path2 = path2.replace(']', '');
- selector = _self.attr('name') + '_' + path1 + '_' + path2 + '_' + path[2];
- }
- var helper = '<span class="help-block">' + errors[k].message + '</span>';
- $('#' + selector).parent().addClass('has-error').append(helper);
- if ($('a[href="#' + $('#' + selector).closest('.tab-pane').attr('id') + '"]').find('i').length == 0)
- $('a[href="#' + $('#' + selector).closest('.tab-pane').attr('id') + '"]').prepend('<i class="fa fa-exclamation-triangle color-red"></i>');
- }
- }
- })
- .always(function () {
- _self.find('[type="submit"]').find('i').remove();
- });
- return false;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement