I"„ (function() { var InvalidField, highlightInvalidFields, mostTargetedElement, parentOrSelf, resetTabIndex, hasProp = {}.hasOwnProperty; parentOrSelf = function(input, selector) { if ($(input).closest(selector).length) { return $(input).closest(selector); } else { return input; } }; mostTargetedElement = function(input, attr) { var element, ref, selector; selector = (ref = $(input).attr(attr)) != null ? ref : $(input.form).attr(attr); return element = parentOrSelf(input, selector); }; InvalidField = (function() { function InvalidField(input1, value1) { var highlightElement, tooltipElement; this.input = input1; this.value = value1; this.input.addClass("invalid-field"); highlightElement = mostTargetedElement(this.input, "data-ei-highlight-element"); highlightElement.addClass("highlight-error"); tooltipElement = mostTargetedElement(this.input, "data-ei-tooltip-element"); $(tooltipElement).tooltip({ tooltipClass: "error-tooltips", position: { my: "left+15 center", at: "right center" } }); $(tooltipElement).attr("title", this.value); } return InvalidField; })(); resetTabIndex = function(form) { return $(form).find(":input").removeAttr("tabindex"); }; highlightInvalidFields = function(form, data) { var btn, errorStr, errors, fieldName, i, input, invalidField, value; resetTabIndex(form); errorStr = data.error().responseText; debugger; console.log("EmphaticInvalid Errors: " + errorStr); errors = $.parseJSON(errorStr); i = 1; for (fieldName in errors) { if (!hasProp.call(errors, fieldName)) continue; value = errors[fieldName]; fieldName = fieldName.replace(".", "_attributes]["); input = $(form).find("[name='" + fieldName + "'], [id='" + fieldName + "'], [name$='[" + fieldName + "]'], [name$='[" + fieldName + "][]'], [data-ei-field-alias='" + fieldName + "']").not(":hidden"); $(input).attr("tabindex", i++); invalidField = new InvalidField(input, value); $(input).on('change', function() { var highlightedElement, tooltipElement; highlightedElement = mostTargetedElement(this, "data-ei-highlight-element"); tooltipElement = mostTargetedElement(this, "data-ei-tooltip-element"); $(highlightedElement).removeClass("highlight-error"); if (!!$(tooltipElement).data("ui-tooltip")) { $(tooltipElement).tooltip("destroy"); } $(tooltipElement).removeAttr("title"); return $(this).removeClass("invalid-field"); }); } $(form).find(".invalid-field").first().focus(); btn = $(form).find("input[type='submit'], button[type='submit'], input[type='image']").first(); return btn.attr("tabindex", i++); }; window.EmphaticInvalids = {}; window.EmphaticInvalids.registerForms = function(selector) { if (selector == null) { selector = "form[data-remote=true]"; } return $("body").on("ajax:error", selector, function(event, data, status, xhr) { return highlightInvalidFields(this, data); }); }; }).call(this); :ET