Skip to content

Commit

Permalink
playing around with handling required
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaynberg committed Sep 14, 2012
1 parent 4b1204c commit 6c9a031
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions select2.js
Expand Up @@ -564,6 +564,9 @@
this.destroy(); this.destroy();
} }


this.required=opts.element.attr("required")!==undefined;
opts.element.removeAttr("required");

this.enabled=true; this.enabled=true;
this.container = this.createContainer(); this.container = this.createContainer();


Expand Down Expand Up @@ -667,6 +670,7 @@
.unbind(".select2") .unbind(".select2")
.show(); .show();
} }
if (this.required) this.opts.element.attr("required", "required");
}, },


// abstract // abstract
Expand Down Expand Up @@ -1943,8 +1947,14 @@
} else { } else {
// we set this to " " instead of "" and later clear it on focus() because there is a firefox bug // we set this to " " instead of "" and later clear it on focus() because there is a firefox bug
// that does not properly render the caret when the field starts out blank // that does not properly render the caret when the field starts out blank
this.search.val(" ").width(10); this.search.val("").width(10);
}

this.search.removeAttr("required");
if (this.required && this.val().length == 0) {
this.search.attr("required", "required");
} }

}, },


// multi // multi
Expand Down Expand Up @@ -2022,11 +2032,10 @@


if (this.opts.closeOnSelect) { if (this.opts.closeOnSelect) {
this.close(); this.close();
this.search.width(10); this.clearSearch();
} else { } else {
if (this.countSelectableResults()>0) { if (this.countSelectableResults()>0) {
this.search.width(10); this.clearSearch();
this.resizeSearch();
this.positionDropdown(); this.positionDropdown();
} else { } else {
// if nothing left to select close // if nothing left to select close
Expand Down Expand Up @@ -2108,6 +2117,8 @@
} }
selected.remove(); selected.remove();
this.triggerChange({ removed: data }); this.triggerChange({ removed: data });

this.clearSearch();
}, },


// multi // multi
Expand Down

0 comments on commit 6c9a031

Please sign in to comment.