terom@6: /** terom@6: * jQuery support code for our forms terom@6: */ terom@6: terom@6: (function($) { terom@6: /* terom@9: * Form field is empty - i.e. null value terom@9: * terom@9: * Pure whitespace also counts terom@9: */ terom@9: $.fn.empty = function () { terom@9: return !this.val() || $.trim(this.val()) == ""; terom@9: } terom@9: terom@9: /** terom@9: * Query or set form field disabled state terom@9: */ terom@9: $.fn.disabled = function (flag) { terom@9: if (flag == undefined) terom@9: // XXX: jQuery returns `true` here? terom@9: return !!this.attr("disabled"); terom@9: terom@9: if (flag) terom@9: this.attr("disabled", "disabled"); terom@9: else terom@9: this.removeAttr("disabled"); terom@9: } terom@9: terom@15: $.fn.checked = function (flag) { terom@15: if (flag == undefined) terom@15: // XXX: jQuery returns true here? terom@15: return !!this.attr("checked"); terom@15: terom@15: terom@15: if (flag) terom@15: this.attr("checked", "checked"); terom@15: else terom@15: this.removeAttr("checked"); terom@15: } terom@15: terom@15: /* terom@15: * The given checkbox acts as an enable/disable toggle for this form control terom@15: */ terom@15: $.fn.formEnabledBy = function (checkbox) { terom@15: var target = this; terom@15: terom@15: checkbox.change(function () { terom@15: target.disabled(!checkbox.checked()); terom@15: }); terom@15: checkbox.change(); terom@15: } terom@15: terom@9: /* terom@6: * When non-zero