Skip to content

Commit

Permalink
Add support for contenteditable tags (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
niceue committed May 9, 2016
1 parent 67b5b3f commit 535fbfa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/jquery.validator.js
Expand Up @@ -237,7 +237,7 @@
return ( name === 'input' && !({submit: 1, button: 1, reset: 1, image: 1})[elem.type] ||
name === 'select' ||
name === 'textarea' ) &&
elem.disabled === false;
elem.disabled === false || elem.getAttribute('contenteditable') !== null;
};

// any value, but not only whitespace
Expand Down Expand Up @@ -1242,12 +1242,12 @@
_getMsgDOM: function(el, msgOpt) {
var $el = $(el), $msgbox, datafor, tgt, container;

if ( $el.is(':input') ) {
if ( $el.is(INPUT_SELECTOR) ) {
tgt = msgOpt.target || attr(el, DATA_TARGET);
if (tgt) {
tgt = isFunction(tgt) ? tgt.call(this, el) : this.$el.find(tgt);
if (tgt.length) {
if ( tgt.is(':input') ) {
if ( tgt.is(INPUT_SELECTOR) ) {
el = tgt.get(0);
} else if ( tgt.hasClass(CLS_MSG_BOX) ) {
$msgbox = tgt;
Expand Down Expand Up @@ -1498,11 +1498,14 @@
*/
function _FieldFactory(context) {
function FieldValue() {
this._valHandler = function() {
return this.element.getAttribute('contenteditable') !== null ? 'text' : 'val';
};
this.getValue = function() {
return $(this.element).val();
return $(this.element)[this._valHandler()]();
};
this.setValue = function(value) {
$(this.element).val(this.value = value);
$(this.element)[this._valHandler()](this.value = value);
};
}
function Field(key) {
Expand Down
2 changes: 1 addition & 1 deletion src/themes/base.styl
Expand Up @@ -36,7 +36,7 @@ inline-block() {
inline-block();
}
.nice-validator {
input, select, textarea {
input, select, textarea, [contenteditable] {
@extend .n-inline-block
}
.msg-container {
Expand Down

0 comments on commit 535fbfa

Please sign in to comment.