for (let i = 0; i < totalElements; i++) {
  if (response.elements[i].validation_error) {
    if(response.elements[i].group_id > 0){
      var tgt;
      var tgtGroup = document.querySelector('.fm_grouped_element_' + response.submission.form_id + '_' + response.elements[i].group_id);
      if(tgtGroup !== undefined && tgtGroup !== null){
        if(response.elements[i].group_type== 1){
          tgt = tgtGroup.querySelector('.gp_fm_'+response.elements[i].group_id);
        }else{
          tgt = tgtGroup.querySelector('.fm_element_' + response.submission.form_id + '_' + response.elements[i].element_id);
        }
      }
    }else{
      tgt = document.querySelector('.fm_element_' + response.submission.form_id + '_' + response.elements[i].element_id);
    }

    if (tgt !== undefined && tgt !== null) {
      tgt.classList.add('has-error');
      var containerErrorClass = response.elements[i].error_classes.element_container;
      var containerClass = response.elements[i].classes.element_container;
      if (containerErrorClass.length > 0) {
        if (containerClass.length > 0) {
          tgt.classList.replace(containerClass, containerErrorClass);
        } else {
          tgt.classList.add(containerErrorClass);
        }
      }
      var tgtInput;
      if(response.elements[i].group_id > 0){
        var _selector = '[name^="formea[group_'+this.mpTarget+']['+response.elements[i].group_id+']['+response.elements[i].setIndex+'][' + response.elements[i].alias + '"]';
        tgtInput = tgt.querySelectorAll(_selector);
      }else{
        tgtInput = tgt.querySelectorAll('[name^="formea[' + response.elements[i].alias + '"]');
      }

      if(tgtInput !== undefined && tgtInput !== null){
        var inputErrorClass = response.elements[i].error_classes.input;
        var inputClass = response.elements[i].classes.input;
        var totalTgtInputs = tgtInput.length;
        if (inputErrorClass.length > 0) {
          for (let j = 0; j < totalTgtInputs; j++) {
            tgtInput[j].classList.add(inputErrorClass);
            tgtInput[j].classList.remove(inputClass);
          }
        }


        var elementFeedback = tgt.getElementsByClassName('fm_feedback_el');

        var errorMsgs = [];
        var totalValidation = response.elements[i].validation_result.result.length;
        for (let j = 0; j < totalValidation; j++) {
          if(response.elements[i].validation_result.result[j].result.result.msg.length > 0){
            errorMsgs.push(response.elements[i].validation_result.result[j].result.result.msg);
          }
        }
        if (elementFeedback !== undefined && elementFeedback !== null) {
          var targetFeedback = elementFeedback.length - 1 ;


          var elementFeedBackErrorClass = response.elements[i].error_classes.feedback_container;
          var elementFeedBackClass = response.elements[i].classes.feedback_container;
          if (elementFeedBackErrorClass.length > 0) {
            elementFeedback[targetFeedback].classList.add(elementFeedBackErrorClass);
          }
          if (elementFeedBackClass.length > 0) {
            elementFeedback[targetFeedback].classList.remove(elementFeedBackClass);
          }
          elementFeedback[targetFeedback].innerHTML = errorMsgs.join('<br/>');
        }
      }
    }
  }
}
